Make setup work with MySQL. Tested. ^^
This commit is contained in:
parent
2b1b640c5d
commit
c1650218e1
1 changed files with 39 additions and 16 deletions
49
setup.py
49
setup.py
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import configparser, os.path, sqlite3, tweepy
|
import configparser, os.path, tweepy, dbtools, getpass
|
||||||
|
|
||||||
if os.path.isfile("config.cfg"):
|
if os.path.isfile("config.cfg"):
|
||||||
print("config.cfg already exists. Please remove it before running this script.")
|
print("config.cfg already exists. Please remove it before running this script.")
|
||||||
|
@ -10,26 +10,49 @@ config = configparser.RawConfigParser()
|
||||||
|
|
||||||
config.add_section('Database')
|
config.add_section('Database')
|
||||||
|
|
||||||
print('''Twitools will use a database for certain tasks. If this file does not exist yet,
|
print('''Twitools will use a database for certain tasks. You can use a file or a MySQL database for this purpose.
|
||||||
it will be created in this process. The file name defaults to 'Database.db'.
|
|
||||||
|
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.
|
||||||
''')
|
''')
|
||||||
|
|
||||||
dbpath = input("Name of the database file [Database.db]: ")
|
dbtype = input("Database type: %i (file), %i (MySQL) [%i]: " % (dbtools.SQLITE, dbtools.MYSQL, dbtools.SQLITE))
|
||||||
print()
|
print()
|
||||||
|
|
||||||
if dbpath == "":
|
try:
|
||||||
dbpath = "Database.db"
|
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)
|
config.set('Database', 'path', dbpath)
|
||||||
|
|
||||||
if os.path.isfile(dbpath):
|
if dbtype == dbtools.MYSQL:
|
||||||
pass
|
db = dbtools.dbObject(dbtype=dbtype, host=dbhost, user=dbuser, pwd=dbpass, db=dbname)
|
||||||
else:
|
else:
|
||||||
conn = sqlite3.connect(dbpath)
|
db = dbtools.dbObject(dbtype=dbtype, path=dbpath)
|
||||||
cur = conn.cursor()
|
if not db.isInitialized():
|
||||||
cur.execute("CREATE TABLE tweets(`tweet_id` INTEGER NOT NULL, `in_reply_to_status_id` TEXT, `in_reply_to_user_id` TEXT, `timestamp` TEXT, `source` TEXT, `text` TEXT, `retweeted_status_id` TEXT, `retweeted_status_user_id` TEXT, `retweeted_status_timestamp` TEXT, `expanded_urls` TEXT, PRIMARY KEY(tweet_id));")
|
db.executeQuery("CREATE TABLE tweets(`tweet_id` INTEGER NOT NULL, `in_reply_to_status_id` TEXT, `in_reply_to_user_id` TEXT, `timestamp` TEXT, `source` TEXT, `text` TEXT, `retweeted_status_id` TEXT, `retweeted_status_user_id` TEXT, `retweeted_status_timestamp` TEXT, `expanded_urls` TEXT, PRIMARY KEY(tweet_id));")
|
||||||
conn.commit()
|
db.commit()
|
||||||
conn.close()
|
|
||||||
|
db.closeConnection()
|
||||||
|
|
||||||
config.add_section("Twitter")
|
config.add_section("Twitter")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue