forked from QuinterApp/Quinter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.py
146 lines (138 loc) · 4.41 KB
/
globals.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
import sys
import shutil
import platform
from GUI import main, misc
import tweak
import os
import twitter as t
import pickle
import timeline
import utils
import threading
import sound
accounts=[]
prefs=None
users=[]
unknown_users=[]
confpath=""
errors=[]
currentAccount=None
timeline_settings=[]
def load():
global timeline_settings
utils.cfu()
global confpath
global prefs
global users
prefs=tweak.Config(name="Quinter",autosave=True)
confpath=prefs.user_config_dir
if platform.system()=="Darwin":
try:
f=open(confpath+"/errors.log","a")
sys.stderr=f
except:
pass
if os.path.exists(confpath+"/sounds/default"):
shutil.rmtree(confpath+"/sounds/default")
if not os.path.exists(confpath+"/sounds"):
os.makedirs(confpath+"/sounds")
if platform.system()=="Darwin":
shutil.copytree("/applications/quinter.app/sounds/default",confpath+"/sounds/default")
else:
shutil.copytree("sounds/default",confpath+"/sounds/default")
uaccounts = os.listdir(confpath+"/..")
for i in uaccounts:
if "Quinter_account" in i:
shutil.move(confpath+"/../"+i,confpath+"/"+i.replace("Quinter_",""))
prefs.user_reversed=prefs.get("user_reversed",False)
prefs.user_limit=prefs.get("user_limit",4)
prefs.tweetTemplate=prefs.get("tweetTemplate","$user.screen_name$: $text$ $created_at$")
prefs.messageTemplate=prefs.get("messageTemplate","$sender.screen_name$ to $recipient.screen_name$: $text$ $created_at$")
prefs.copyTemplate=prefs.get("copyTemplate","$user.name$ ($user.screen_name$): $text$")
prefs.retweetTemplate=prefs.get("retweetTemplate","Retweeting $user.name$ ($user.screen_name$): $text$")
prefs.quoteTemplate=prefs.get("quoteTemplate","Quoting $user.name$ ($user.screen_name$): $text$")
prefs.userTemplate=prefs.get("userTemplate","$name$ ($screen_name$): $followers_count$ followers, $friends_count$ friends, $statuses_count$ tweets. Bio: $description$")
prefs.accounts=prefs.get("accounts",1)
prefs.streaming=prefs.get("streaming",False)
prefs.invisible=prefs.get("invisible",False)
prefs.invisible_sync=prefs.get("invisible_sync",True)
prefs.update_time=prefs.get("update_time",2)
prefs.volume=prefs.get("volume",1.0)
prefs.count=prefs.get("count",200)
prefs.repeat=prefs.get("repeat",False)
prefs.demojify=prefs.get("demojify",False)
prefs.demojify_tweet=prefs.get("demojify_tweet",False)
prefs.position=prefs.get("position",True)
prefs.chars_sent=prefs.get("chars_sent",0)
prefs.tweets_sent=prefs.get("tweets_sent",0)
prefs.replies_sent=prefs.get("replies_sent",0)
prefs.quotes_sent=prefs.get("quotes_sent",0)
prefs.retweets_sent=prefs.get("retweets_sent",0)
prefs.likes_sent=prefs.get("likes_sent",0)
prefs.statuses_received=prefs.get("statuses_received",0)
prefs.ask_dismiss=prefs.get("ask_dismiss",True)
prefs.reversed=prefs.get("reversed",False)
prefs.window_shown=prefs.get("window_shown",True)
prefs.media_player=prefs.get("media_player","")
prefs.earcon_audio=prefs.get("earcon_audio",True)
prefs.earcon_top=prefs.get("earcon_top",False)
prefs.wrap=prefs.get("wrap",False)
if prefs.invisible:
main.window.register_keys()
try:
f=open(confpath+"/usercache","rb")
users=pickle.loads(f.read())
f.close()
except:
pass
if prefs.user_reversed==False:
users=[]
prefs.user_reversed=True
load_timeline_settings()
for i in range(0,prefs.accounts):
add_session()
def add_session():
global accounts
accounts.append(t.twitter(len(accounts)))
def save_users():
global users
f=open(confpath+"/usercache","wb")
f.write(pickle.dumps(users))
f.close()
def save_messages(account,messages):
f=open(account.confpath+"/messagecache","wb")
f.write(pickle.dumps(messages))
f.close()
def load_messages(account):
try:
f=open(account.confpath+"/messagecache","rb")
messages=pickle.loads(f.read())
f.close()
return messages
except:
return None
def save_timeline_settings():
global confpath
global timeline_settings
f=open(confpath+"/timelinecache","wb")
f.write(pickle.dumps(timeline_settings))
f.close()
def load_timeline_settings():
global confpath
global timeline_settings
try:
f=open(confpath+"/timelinecache","rb")
timeline_settings=pickle.loads(f.read())
f.close()
except:
return False
def get_timeline_settings(account_id,name):
global timeline_settings
for i in timeline_settings:
if i.tl==name and i.account_id==account_id:
return i
timeline_settings.append(timeline.TimelineSettings(account_id,name))
return timeline_settings[len(timeline_settings)-1]
def clean_users():
global users
users=[]