From ca466277a5c573f862b1ad67dbb90499285a7ae8 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 8 Feb 2017 13:17:14 +0100 Subject: [PATCH] Copy over setup.py from twitools --- setup.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 setup.py diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..a5e2df3 --- /dev/null +++ b/setup.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 + +import configparser, os.path, tweepy, dbtools, getpass + +if os.path.isfile("config.cfg"): + print("config.cfg already exists. Please remove it before running this script.") + exit(1) + +config = configparser.RawConfigParser() + +config.add_section('Database') + +print('''TweepBot will use a database for certain tasks. You can use a file or a MySQL database for this purpose. + +If you wish to use a MySQL database, you will need the credentials for it. If you don't know what any of that means, stick with the default value and just press Enter. +''') + +dbtype = input("Database type: %i (file), %i (MySQL) [%i]: " % (dbtools.SQLITE, dbtools.MYSQL, dbtools.SQLITE)) +print() + +try: + dbtype = int(dbtype) +except: + pass + +if dbtype == dbtools.MYSQL: + dbhost = input("MySQL host [localhost]: ") or "localhost" + dbuser = input("MySQL username [twitools]: ") or "twitools" + dbpass = getpass.getpass("MySQL password (not echoed!): ") + dbname = input("MySQL database name [twitools]: ") or "twitools" + print() + + config.set('Database', 'type', dbtype) + config.set('Database', 'host', dbhost) + config.set('Database', 'user', dbuser) + config.set('Database', 'pass', dbpass) + config.set('Database', 'name', dbname) + +else: + dbtype = dbtools.SQLITE + dbpath = input("Name of the database file [Database.db]: ") or "Database.db" + print() + + config.set('Database', 'type', dbtype) + config.set('Database', 'path', dbpath) + +if dbtype == dbtools.MYSQL: + db = dbtools.dbObject(dbtype=dbtype, host=dbhost, user=dbuser, pwd=dbpass, db=dbname) +else: + db = dbtools.dbObject(dbtype=dbtype, path=dbpath) +if not db.isInitialized(): + db.executeQuery("CREATE TABLE tokens(`cid` INT PRIMARY KEY, `ato` TEXT, `ase` TEXT, `fish` INT);") + db.commit() + +db.closeConnection() + +config.add_section("Twitter") + +cke = input("Your Twitter application's consumer key: ") +cse = input("Your Twitter application's consumer secret: ") + +config.set("Twitter", "cke", cke) +config.set("Twitter", "cse", cse) + +print("Seems like everything worked out fine. Let's write that config file...") + +with open('config.cfg', 'wt') as cfg: + config.write(cfg) + +print("We're all done. You can now use Twitools. Have fun!")