-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
182 lines (148 loc) · 6.67 KB
/
app.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
import PySimpleGUI as sg
from telegraph import Telegraph
import clipboard, webbrowser
# ---------------------------------------------------------------
# _ _ _
# | |_ ___| | ___ __ _ _ __ __ _ _ __ | |__
# | __/ _ \ |/ _ \/ _` | '__/ _` | | '_ \| '_ \
# | || __/ | __/ (_| | | | (_| |_| |_) | | | |
# \__\___|_|\___|\__, |_| \__,_(_) .__/|_| |_|
# |___/ |_|
#
#---------------------------------------------------------------
def postar(user, title, content):
telegraph = Telegraph()
try:
telegraph.create_account(short_name=user)
response = telegraph.create_page(title, html_content=content)
mensagem = (response['url'])
clipboard.copy(mensagem)
sg.popup_timed('Link gerado!!',
f'O link <{mensagem}> já está em sua área de transferência\nUse CTRL+V para colar onde deseja compartilhar...')
except:
sg.popup_error('Erro!',
'Mensagem não publicada...',
'Verifique sua conexão de internet ou mude o seu nome de usuário...')
#---------------------------------------------------------------
def manual():
sg.Popup('Manual',
'PyPost Telegra.ph é uma versão gráfica para o site http://telegra.ph',
'Preencha com um título, crie um nome de usuário (pode ser fictício), crie o conteúdo e clique no botão [Publicar no Telegra.ph] ',
'Cole o link que é gerado na área da transferência, tente [CTRL]+[V]',
'Telegra.ph é um sistema de postagens anônimo do Telegram. Basta criar uma postagem e compartilhar o link da postagem gerado no Facebook, Twitter ou qualquer outro lugar...',
'Telegra.ph tem suporte a links e incorporação do Youtube, Vimeo, twitter e outros...',
'PyPost Telegra.ph foi escrito inteiramente em Python e usa a API telegra.ph e pysimplegui para interface gráfica...',
'Obrigado por usar o PyPost Telegra.ph')
#---------------------------------------------------------------
sg.theme('SystemDefaultForReal')
heart = b'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAm0lEQVRYhe2Vyw2AIBBER2NFUAqWKaVAS3oy0Q3CLp9wcN+RZJjHJwAoyt9Z6MBhzMkJ7jG+srW5qknoZLU5AFglwRFsLWHpylNM3wEVUAEVKAq4EIYKsP4CFwK8tV0K6V/AOgJv7bCdYN+BHhJ09UDiCG56vPOl8qxAT5GvcpZAq0iuXCQgFSkVVwuUJLjFTQJUQlr6ZPpTrCgXkhg7Ez2kfusAAAAASUVORK5CYII='
menu = [['&Arquivo',
['&Texto',
['&Abrir',
'&Salvar'],
'&Publicar',
'&Limpar',
'&Sair']],
['&Editar',
['&Copiar',
'&Colar']],
['&Formatar',
['&Negrito',
'&Itálico']],
['&Inserir',
['&Imagem',
'&Link',
'&Lista',
'&Parágrafo']],
['&Ajuda',
['&Manual',
'&Autor',
['&GitHub',
'&Linkedin']]]
]
layout = [[sg.Menu(menu)],
[sg.Text('Título da postagem:')],
[sg.Input(key='-title-', size=(1000,1))],
[sg.Text('Autoria (seu nome):')],
[sg.Input(key='-autor-', size=(1000,1))],
[sg.Text('Conteúdo: Use texto simples para parágrafos únicos ou html para textos formatados:')],
[sg.Multiline(key='-content-', size=(1000,12))],
[sg.Text('', size=(5, 1))],
[sg.Stretch(),
sg.Button('Publicar no Telegra.ph', font=('Arial', 18)),
sg.Stretch()],
[sg.Text('', size=(5, 1))],
[sg.Stretch(), sg.Text('Software feito com o', font=('Courier', 10), size=(20, 1)), sg.Image(heart)]]
window = sg.Window('PyPost Telegra.ph', layout, size=(640, 480), resizable=True)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Sair':
break
elif event == 'Limpar':
window['-autor-'].update('')
window['-title-'].update('')
window['-content-'].update('')
elif event == 'Publicar' or event == 'Publicar no Telegra.ph':
user = values['-autor-']
title = values['-title-']
content = values['-content-']
postar(user, title, content)
elif event == 'Abrir':
with open('.temp.txt', 'r') as content:
window['-content-'].update(content.read())
elif event == 'Salvar':
content = values['-content-']
with open('.temp.txt','w') as arquivo:
arquivo.write(content)
sg.popup_timed('Arquivo salvo',
'Seu texto foi salvo no computador',
'Use o menu "Arquivo->Texto->Abrir"')
elif event == 'Copiar':
content = values['-content-']
clipboard.copy(content)
sg.popup_timed('Texto copiado',
'Todo o conteudo da postagem foi copiado para a área de transferência.',
'Use Ctrl+V para colar o conteúdo no local desejado...')
elif event == 'Colar':
content = values['-content-']
copiado = clipboard.paste()
content += f' {copiado}'
window['-content-'].update(content)
elif event == 'Negrito':
content = values['-content-']
content += f' <b> Seu texto aqui </b>'
window['-content-'].update(content)
elif event == 'Parágrafo':
content = values['-content-']
content += f'''
<p> Seu texto aqui </p>
'''
window['-content-'].update(content)
elif event == 'Itálico':
content = values['-content-']
content += f' <i> Seu texto aqui </i>'
window['-content-'].update(content)
elif event == 'Imagem':
content = values['-content-']
content += f'''
<p><img src="Link da sua imagem"></p>'''
window['-content-'].update(content)
elif event == 'Link':
content = values['-content-']
content += f' <a href="link da internet">editar este texto</a>'
window['-content-'].update(content)
elif event == 'Lista':
content = values['-content-']
content += f'''
<p><ol>
<li>Editar esse texto</li><li>Editar esse texto</li><li>Editar esse texto</li>
</ol></p>
'''
window['-content-'].update(content)
elif event == 'Manual':
manual()
elif event == 'GitHub':
webbrowser.open('https://github.com/elizeubarbosaabreu/PyPost-Telegra.ph.git')
elif event == 'Linkedin':
webbrowser.open('https://www.linkedin.com/in/elizeu-barbosa-abreu-69965b218/')
window.close()