diff options
author | neodarz <neodarz@neodarz.net> | 2019-01-13 18:34:54 +0100 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-01-13 18:34:54 +0100 |
commit | 07cc1fdc7e79468a6e8d9b53048712b652f8da84 (patch) | |
tree | bb668d7e82684d40972c078b089499e7e1919146 /app.py | |
parent | 6648b7f66836d630b5b3ef5399c4c0cf4fb6f65b (diff) | |
download | khanindexer-07cc1fdc7e79468a6e8d9b53048712b652f8da84.tar.xz khanindexer-07cc1fdc7e79468a6e8d9b53048712b652f8da84.zip |
Migrate to PostgreSQL
Diffstat (limited to '')
-rw-r--r-- | app.py | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -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() |