-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet.py
executable file
·68 lines (48 loc) · 1.77 KB
/
tweet.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
#!/usr/bin/env python3
# Requires sudo apt-get install python3-tk
from time import sleep
from PySimpleGUI import Window, Input, FileBrowse, Button, theme, Text
import tweepy
# SETUP KEYS ///////////////////////////////
_keys = dict(
username="@USERNAME",
consumer_key='KEY',
consumer_secret='KEY',
access_token='KEY',
access_token_secret='KEY'
)
# CREATE AUTHORIZATION /////////////////////
_auth = tweepy.OAuthHandler(_keys['consumer_key'], _keys['consumer_secret'])
_auth.set_access_token(_keys['access_token'], _keys['access_token_secret'])
_API = tweepy.API(_auth)
# ///////////////////////////////////////// MAIN CODE ///////////////////////////////////////
theme('BluePurple') # Set color theme
_layout = [[Text('Type your Tweet '), Text(size=(22, 1), key='-OUT-')],
[Input(key='-TXT-')],
[Text('')],
[Text('Choose image (Optional)')],
[Input(key='-IMG-'), FileBrowse()],
[Button('TXT Post'), Button('IMG Post'), Button(' EXIT ')]]
_window = Window('Tweet GUI', _layout, icon="assets/twitter.png") # Set title & icon
# _window = Window('Tweet GUI', _layout, no_titlebar=True, alpha_channel=1, grab_anywhere=True)
# DEFINE POSTING ////////////////////
def tweet():
_API.update_status((values['-TXT-']))
sleep(1)
def tweet_photo():
status = values['-TXT-']
x = values['-IMG-']
_API.update_with_media(filename=x, status=status)
sleep(2)
while True: # Event Loop
event, values = _window.read()
print(event, values)
if event in (None, ' EXIT '):
break
if event == 'TXT Post':
_window['-OUT-'].update('Tweet Sent!')
tweet()
if event == 'IMG Post':
_window['-OUT-'].update('Tweet w/ IMG Sent!')
tweet_photo()
_window.close()