sbtools/setup.py
2017-01-31 00:52:56 +01:00

79 lines
2.5 KiB
Python
Executable file

#!/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('''Romeotools 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 messages(`id` INTEGER NOT NULL, `text` TEXT, `sender_id` VARCHAR(60), `recipient_id` VARCHAR(60), `created_at` TEXT, PRIMARY KEY(id));")
db.executeQuery("CREATE TABLE photos(`mid` TEXT, `pid` TEXT);")
db.commit()
db.closeConnection()
config.add_section("Romeo")
print('''In the next step, we'll get you connected to PlanetRomeo. For this, we
will need your username and password. Please note that these will be stored on
your hard disk in plain text. Sadly PlanetRomeo doesn't offer a better way for
third party applications to authenticate...
''')
unam = input("Username: ")
pwrd = getpass.getpass("Password (not echoed back!): ")
print()
config.set("Romeo", "user", unam)
config.set("Romeo", "pass", pwrd)
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!")