-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWolf's Den.py
166 lines (156 loc) · 5.57 KB
/
Wolf's Den.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
"""
__ __ _ __ _ ____
\ \ / /__ | |/ _( )___ | _ \ ___ _ __
\ \ /\ / / _ \| | |_|// __| | | | |/ _ \ '_ \
\ V V / (_) | | _| \__ \ | |_| | __/ | | |
\_/\_/ \___/|_|_| |___/ |____/ \___|_| |_|
|----------------------------------------------------------|
|Wolf's Den - a lightweight Twitter client in Python |
|Copyright (C) Eric Sund |
| |
|The full GNU GPLv3 license is found at /LICENSE.txt |
|----------------------------------------------------------|
Wolf's Den makes use of the following unmodified libraries:
> EasyGUI 0.96 Copyright (c) 2010, Stephen Raymond Ferg (Revised BSD License)
> Tweepy 2.1 Copyright (c) 2009-2010 Joshua Roesslein (MIT License)
> Twython 3.1.0 Copyright (c) 2013 Ryan McGrath (MIT License)
Bugs:
None currently known
"""
#!/usr/bin/env python
import sys, os, twython, easygui, tweepy
from easygui import *
from twython import Twython
#Wolf's Den app keys
consumer_key = 'oJFCnwf9pOu2LIT8rvs4nQ'
consumer_secret = 'rVDUj8TknQc9GA0Eqz7uvGo7aAYah3FRSqJqhjXZ66k'
#check for existing authentication
KeysExist = open("userkeys.txt", "r")
readKeysExist = KeysExist.readline()
authTrue = readKeysExist[0]
if authTrue == "0": #if no authentication
#get user keys
auth = tweepy.auth.OAuthHandler(consumer_key, consumer_secret, secure = True)
auth_url = auth.get_authorization_url()
enterbox("Please obtain your PIN here: ", "Authorize Wolf's Den", auth_url)
pin = enterbox('Enter PIN: ').strip()
auth.get_access_token(pin)
accessKey = auth.access_token.key
accessSecret = auth.access_token.secret
accessKey = str(accessKey)
accessSecret = str(accessSecret)
#save user keys
with open('userkeys.txt', 'r') as file:
fileContents = file.readlines()
fileContents[0] = "1\n"
fileContents[1] = accessKey + "\n"
fileContents[2] = accessSecret + "\n"
with open('userkeys.txt', 'w') as file:
file.writelines(fileContents)
KeysExist.close()
#read keys
getUserKeys = open("userkeys.txt", "r+")
readUserKeys = getUserKeys.readlines()
accessKey = readUserKeys[1]
accessSecret = readUserKeys[2]
accessKey = accessKey[:-1]
accessSecret = accessSecret[:-1]
t = Twython(consumer_key, consumer_secret, accessKey, accessSecret)
tweetErrors = (
("There was a problem sending your tweet! Check your network connection and userkeys file!"),
("You've reached the maximum API calls! Wait before trying again."),
("Problem! - Wolf's Den")
)
def tweetAttempt(): #media syntax
try:
t.update_status_with_media(media = m, status = s)
tweeting = False
except twython.TwythonError:
msgbox(tweetErrors[0], tweetErrors[2], "Try Again!")
except twython.TwythonRateLimitError:
msgbox(tweetErrors[1], tweetErrors[2], "Okay")
else:
msgbox("Tweet sent!", "Wolf's Den", "Okay")
on = True
while on:
menu = buttonbox(" ", "Wolf's Den", ["Tweet", "Customize", "Close", "Sign Out"])
if menu == "Tweet":
INtweetmenu = True
while INtweetmenu:
tweetmenu = buttonbox(" ", "Tweet - Wolf's Den", ["Tweet", "Tweet Photo", "Back"])
if tweetmenu == "Tweet":
tweeting = True
while tweeting:
s = enterbox("What's happening?", "New Tweet - Wolf's Den")
if s == None: tweeting = False
else:
try:
t.update_status(status = s)
tweeting = False
INtweetmenu = False
except twython.TwythonError:
msgbox(tweetErrors[0], tweetErrors[2], "Try Again!")
except twython.TwythonRateLimitError:
msgbox(tweetErrors[1], tweetErrors[2], "Okay")
else:
msgbox("Tweet sent!", "Wolf's Den", "Okay")
elif tweetmenu == "Tweet Photo":
tweeting = True
while tweeting:
m = fileopenbox("Select Picture - Wolf's Den", "Tweet Photo")
m = open(m, "r")
s = enterbox("Say something about this photo!", "Tweet Photo - Wolf's Den")
if s == None: tweeting = False
else:
if s == "":
tweetAttempt()
tweeting = False
INtweetmenu = False
if s != "":
tweetAttempt()
tweeting = False
INtweetmenu = False
elif tweetmenu == "Back":
INtweetmenu = False
elif menu == "Customize":
customizing = True
while customizing:
customizeMenu = buttonbox(" ", "Customize - Wolf's Den", ["Profile Picture", "Cover Photo", "Background Image", "Back"])
if customizeMenu == "Profile Picture":
updatePic = True
while updatePic:
pic = fileopenbox("Select Picture - Wolf's Den", "Update Profile Picture")
pic = open(pic, 'r')
try:
t.update_profile_image(image = pic)
updatePic = False
except twython.TwythonError:
msgbox(tweetErrors[0], tweetErrors[2], "Try Again!")
except twythonTwythonRateLimitError:
msgbox(tweetErrors[1], tweetErrors[2], "Okay")
else:
msgbox("Profile picture updated!", "Wolf's Den", "Okay")
elif customizeMenu == "Cover Photo":
"""
In Development
---------------------------------------------
#img = open("test.jpg", "rb")
#t.update_profile_banner_image(banner = img)
---------------------------------------------
"""
msgbox("In development.")
elif customizeMenu == "Background Image":
msgbox("In development")
elif customizeMenu == "Back":
customizing = False
elif menu == "Close":
on = False
elif menu == "Sign Out":
with open('userkeys.txt', 'r') as file:
fileContents = file.readlines() #set access secret and key to blank lines
fileContents[0] = "0\n"
fileContents[1] = "\n"
fileContents[2] = "\n"
with open('userkeys.txt', 'w') as file:
file.writelines(fileContents)
on = False