示例#1
0
 def __init__(self, identifier, stream_handler, account_handler, url, action_func):
     self.identifier = identifier
     threading.Thread.__init__(self)
     self.stream_handler = stream_handler
     self.handler = account_handler
     self.conn = functions.db_connect(url)
     print("Database connection successful.")
     self.cur = self.conn.cursor()
     self.db_access = {'conn': self.conn, 'cur': self.cur, 'url': url}  # To encapsulate db access data.
     self.action_func = action_func
示例#2
0
 def __init__(self, handler, upload_handler, url, sleep_time, fav, retweet, follow, scrape):
     threading.Thread.__init__(self)
     self.handler = handler
     self.upload_handler = upload_handler
     self.conn = functions.db_connect(url)
     print("Database connection successful.")
     self.cur = self.conn.cursor()
     self.db_access = {'conn': self.conn, 'cur': self.cur, 'url': url}  # To encapsulate db access data.
     self.sleep_time = sleep_time
     self.fav = fav
     self.retweet = retweet
     self.follow = follow
     self.scrape = scrape
     print('sleep_time: %s, fav: %s, retweet: %s, follow: %s, scrape: %s' %
           (self.sleep_time, self.fav, self.retweet, self.follow, self.scrape)
          )
示例#3
0
#!/usr/bin/env python3
"""Script for initializing credentials and database for the bot."""
# Bound to change (a lot!)

import argparse
from urllib.parse import urlparse
from chirps.functions import db_connect

parser = argparse.ArgumentParser()
parser.add_argument("db_url", help="Postgres database url")
args = parser.parse_args()

url = urlparse(args.db_url)
conn = db_connect(url)
cur = conn.cursor()

# Create database.
cur.execute("CREATE TABLE keywords(word varchar)")
conn.commit()
print("Enter keywords to be followed one by one. When done, type 'exit':")
words = []
while True:
    word = input()
    if word.lower() == "exit":
        break
    words.append(word)

for word in words:
    cur.execute("INSERT INTO keywords VALUES(%s)", (word, ))
conn.commit()