-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
100 lines (84 loc) · 4.51 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# setup.py
# description: Very quick and dirty setup script to create tables in DB
# copyrigtht: 2015 William Patton - PattonWebz
# licence: GPLv3
# @package: PWTwitterBot
import dbconnect
from configuration import dbconfig
def dropTableFunction(cursor, query):
try :
cursor.execute(query)
except :
print("Doesn't exist, will create.")
else :
print("Dropped")
def getDefaultKeys(cursor):
print("Enter the access credentials for the default user account.")
inConsumerKey = raw_input('Consumer Key = ')
inConsumerSecret = raw_input('Consumer Secret = ')
inAccessKey = raw_input('Access Key = ')
inAccessSecret = raw_input('Access Secret = ')
insertAccountQuery = ('INSERT INTO Accounts '
'(user, CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET) '
'VALUES '
'("default", "%s", "%s", "%s", "%s")' % (inConsumerKey, inConsumerSecret, inAccessKey, inAccessSecret))
cursor.execute(insertAccountQuery)
def main():
cnx = dbconnect.dbconnect(dbconfig)
cursor = dbconnect.dbcursor(cnx)
dropQuery_Accounts = ('DROP TABLE IF EXISTS Accounts')
createQuery_Accounts = ('CREATE TABLE Accounts ('
'id int(4) unsigned NOT NULL AUTO_INCREMENT, '
'user varchar(32) NOT NULL, '
'CONSUMER_KEY varchar(140) NOT NULL, '
'CONSUMER_SECRET varchar(140) NOT NULL, '
'ACCESS_KEY varchar(140) NOT NULL, '
'ACCESS_SECRET varchar(140) NOT NULL, '
'PRIMARY KEY (id))'
)
dropTableFunction(cursor, dropQuery_Accounts)
cursor.execute(createQuery_Accounts)
dropQuery_ScheduledTweets = ('DROP TABLE IF EXISTS ScheduledTweets')
createQuery_ScheduledTweets = ('CREATE TABLE ScheduledTweets ('
'id int(6) unsigned NOT NULL AUTO_INCREMENT, '
'tweetcontent blob NOT NULL, '
'timetosend datetime NOT NULL, '
'sent tinyint(1) NOT NULL, '
'timesent timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, '
'done tinyint(1) NOT NULL, '
'tweettype varchar(16) NOT NULL DEFAULT "tweet", '
'PRIMARY KEY (id))'
)
dropTableFunction(cursor, dropQuery_ScheduledTweets)
cursor.execute(createQuery_ScheduledTweets)
dropQuery_SearchedForTweets = ('DROP TABLE IF EXISTS SearchedForTweets')
createQuery_SearchedForTweets = ('CREATE TABLE SearchedForTweets ('
'id int(6) unsigned NOT NULL AUTO_INCREMENT, '
'tweetid varchar(20) NOT NULL, '
'username varchar(20) NOT NULL, '
'tweetcontent varchar(1024) NOT NULL, '
'timesent datetime NOT NULL, '
'searchterm varchar(128) DEFAULT NULL, '
'PRIMARY KEY (id), '
'UNIQUE KEY id (id), '
'UNIQUE KEY tweetid (tweetid))'
)
dropTableFunction(cursor, dropQuery_SearchedForTweets)
cursor.execute(createQuery_SearchedForTweets)
dropQuery_SentTweets = ('DROP TABLE IF EXISTS SentTweets')
createQuery_SentTweets = ('CREATE TABLE SentTweets ('
'id int(6) unsigned NOT NULL AUTO_INCREMENT, '
'tweetcontent varchar(140) NOT NULL, '
'timetosend datetime NOT NULL, '
'oldid int(6) NOT NULL DEFAULT 202, '
'sent tinyint(1) NOT NULL, '
'timesent timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, '
'PRIMARY KEY (id))'
)
dropTableFunction(cursor, dropQuery_SentTweets)
cursor.execute(createQuery_SentTweets)
getDefaultKeys(cursor)
cnx.commit()
if __name__ =='__main__':
main()