aboutsummaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-01-13 18:34:54 +0100
committerneodarz <neodarz@neodarz.net>2019-01-13 18:34:54 +0100
commit07cc1fdc7e79468a6e8d9b53048712b652f8da84 (patch)
treebb668d7e82684d40972c078b089499e7e1919146 /app.py
parent6648b7f66836d630b5b3ef5399c4c0cf4fb6f65b (diff)
downloadkhanindexer-07cc1fdc7e79468a6e8d9b53048712b652f8da84.tar.xz
khanindexer-07cc1fdc7e79468a6e8d9b53048712b652f8da84.zip
Migrate to PostgreSQL
Diffstat (limited to '')
-rw-r--r--app.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/app.py b/app.py
index 281f932..ee04e3d 100644
--- a/app.py
+++ b/app.py
@@ -1,6 +1,8 @@
import scrapy
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
+from psycopg2 import connect
+from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
from crawler.neodarznet.spiders.scrape import ScrapSpider
@@ -10,7 +12,17 @@ import config
process = CrawlerProcess(get_project_settings())
def main():
- db.create_tables([Page])
+
+ try:
+ db.create_tables([Page])
+ except:
+ con = connect(user=config.DB_USER, host=config.DB_HOST, password=config.DB_PASS)
+ con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
+ cur = con.cursor()
+ cur.execute('CREATE DATABASE '+config.DB+';')
+ cur.close()
+ con.close()
+ db.create_tables([Page])
process.crawl(ScrapSpider)
process.start()