-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathconfig.py
219 lines (185 loc) · 6.99 KB
/
config.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import configparser
import os
config = configparser.RawConfigParser()
config.optionxform = str #not to convert config to lowercase
config.read('config.ini')
__vMajor__ = '3'
__vMinor__ = '8'
__vPatch__ = '0'
__vRel__ = 'e'
__version__ = __vMajor__ + '.' + __vMinor__ + '.' + __vPatch__ + __vRel__
BotToken = config.get('Bot','BotToken')
BotName = config.get('Bot','BotName')
GitHubToken = config.get('GitHub','GitHubToken')
GitHubBranch = config.get('GitHub','GitHubBranch')
GitHubUser = config.get('GitHub','GitHubUser')
GitHubRepo = config.get('GitHub','GitHubRepo')
GitHubAuthor = config.get('GitHub','GitHubAuthor')
GitHubEmail = config.get('GitHub','GitHubEmail')
hour24 = (config.get('Misc','hour24')).lower()
defaultIndentLevel = (config.get('Misc','defaultIndentLevel'))
journalsFilesFormat = (config.get('Misc','journalsFilesFormat'))
journalsFilesExtension = (config.get('Misc','journalsFilesExtension'))
journalsFolder = (config.get('Misc','journalsFolder'))
journalsPrefix = (config.get('Misc','journalsPrefix'))
# TODOCommand = (config.get('Misc','TODOCommand'))
BookmarkTag = (config.get('Misc','BookmarkTag'))
assetsFolder = (config.get('Misc','assetsFolder'))
hypothesisToken = (config.get('hypothesis','hypothesisToken'))
hypothesisUsername = (config.get('hypothesis','hypothesisUsername'))
manageHypothesisUpdates = (config.get('hypothesis','manageHypothesisUpdates')).lower()
embedHypothesisAnnotations = (config.get('hypothesis','embedHypothesisAnnotations')).lower()
hypothesisTagSpaceHandler = (config.get('hypothesis','hypothesisTagSpaceHandler'))
def isBotAuthorized(chat_id):
isBotAuthorizedID = False
for BotAuthorizedId in getBotAuthorizedIDs():
if str(chat_id) == str(BotAuthorizedId):
isBotAuthorizedID = True
return isBotAuthorizedID
def isNewer():
try:
LastVersionRun = config.get('Bot', 'LastVersionRun')
if(__version__ != LastVersionRun):
config.set('Bot', 'LastVersionRun', __version__)
with open('config.ini', 'w') as configfile:
config.write(configfile)
return True
else:
return False
except:
config.set('Bot', 'LastVersionRun', __version__)
with open('config.ini', 'w') as configfile:
config.write(configfile)
return True
def getBotVersion():
return __version__
def getBotAuthorizedIDs():
return config.get('Bot','BotAuthorizedIDs').split(',')
def isManageHypothesis():
if manageHypothesisUpdates == 'true':
return True
else:
return False
def isHypothesisEmbedded():
if embedHypothesisAnnotations == 'true':
return True
else:
return False
def getHypothesisTagSpaceHandler():
return hypothesisTagSpaceHandler
def getAssetsFolder():
return assetsFolder
def getAssetsDestination():
return config.get('Bot','assetsDestination').lower()
def getFirebaseBucketName():
return config.get('Firebase','BucketName')
def getflashcardDailyGoal():
return int(config.get('TimeSpacedRepetion', 'flashcardDailyGoal'))
def getflashcardsTag():
return config.get('TimeSpacedRepetion', 'flashcardTag')
def getlastNewsDisplayed():
try:
lastNewsDisplayed = config.get('Bot', 'lastNewsDisplayed')
except:
lastNewsDisplayed = 0
config.set('Bot', 'lastNewsDisplayed', lastNewsDisplayed)
with open('config.ini', 'w') as configfile:
config.write(configfile)
return lastNewsDisplayed
def setlastNewsDisplayed(newsid):
config.set('Bot', 'lastNewsDisplayed', newsid)
with open('config.ini', 'w') as configfile:
config.write(configfile)
def getGitHubUpdateFrequency():
try:
return int(config.get('GitHub', 'GitHubUpdateFrequency'))*60
except:
config.set('GitHub', 'GitHubUpdateFrequency', '720')
with open('config.ini', 'w') as configfile:
config.write(configfile)
return 43200
def isCalendarsAutogenerated():
moveConfigSection('Bot','CalendarOptions', 'autoGenerateCalendars')
try:
if config.get('CalendarOptions', 'autoGenerateCalendars') == 'true':
return True
else:
return False
except:
config.set('CalendarOptions', 'autoGenerateCalendars', 'false')
with open('config.ini', 'w') as configfile:
config.write(configfile)
return False
def getfirstDayOfWeek():
moveConfigSection('Misc', 'CalendarOptions', 'firstDayOfWeek')
return int(config.get('CalendarOptions', 'firstDayOfWeek'))
def getcalendarFile():
moveConfigSection('Misc','CalendarOptions', 'calendarFile')
return config.get('CalendarOptions', 'calendarFile')
def isEntryTimestamped():
try:
if config.get('Bot', 'timestampEntries') == 'true':
return True
else:
return False
except:
config.set('Bot', 'timestampEntries', 'true')
with open('config.ini', 'w') as configfile:
config.write(configfile)
return True
def getCommandsMap():
from ast import literal_eval
try:
return literal_eval(config.get('Misc', 'CommandsMap'))
except:
CommandsMap = "{'TODO':'TODO', 'LATER':'LATER'}"
config.set('Misc', 'CommandsMap', CommandsMap)
with open('config.ini', 'w') as configfile:
config.write(configfile)
return literal_eval(CommandsMap)
def getMonths2Generate():
try:
return config.get('CalendarOptions', 'generateMonths').split(',')
except:
generateMonths = "1,1"
config.set('CalendarOptions', 'generateMonths', generateMonths)
with open('config.ini', 'w') as configfile:
config.write(configfile)
return ["1","1"]
def moveConfigSection(oldSection, newSection, key):
try:
keyVal = config.get(oldSection, key)
config.remove_option(oldSection,key)
try:
config.add_section(newSection)
except:
pass
config.set(newSection, key, keyVal)
with open('config.ini', 'w') as configfile:
config.write(configfile)
except:
pass
def getAgePublicKey():
return config.get('AgeEncryption', 'AgePublicKey')
def generateAgeKeyFile():
keys_filename = os.path.expanduser("~/.config/age/keys.txt")
KEYFILE = "# created: 2020-02-25T00:00:00\n# {}\n{}\n".format(getAgePublicKey(),config.get('AgeEncryption', 'AgePrivateKey'))
# with open(keys_filename, 'w') as f:
f = open(keys_filename, 'w')
f.write(KEYFILE)
f.close()
def isGraphAgeEncrypted():
try:
if config.get('AgeEncryption', 'AgeEncrypted') == 'true':
return True
else:
return False
except:
config.set('AgeEncryption', 'AgeEncrypted', 'false')
with open('config.ini', 'w') as configfile:
config.write(configfile)
return False
def setGraphAgeEncrypted(state):
config.set('AgeEncryption', 'AgeEncrypted', state)
with open('config.ini', 'w') as configfile:
config.write(configfile)