-
Notifications
You must be signed in to change notification settings - Fork 0
/
xyz2flomo.py
executable file
·60 lines (46 loc) · 1.51 KB
/
xyz2flomo.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
from bs4 import BeautifulSoup as bs
import requests
import json
import sys
import flomo
from config import cookies, notify_config
def notify(t, m):
flomo.notify(t, m, **notify_config)
cmd = sys.argv[1].split(' ')
url = cmd[0]
# url = 'https://www.xiaoyuzhoufm.com/episode/5e280fab418a84a0461fa936?s=eyJ1IjoiNWVmMWM2YTBiMzY1ZmE4MzI0OWIzZWNhIn0%3D%0A'
if len(cmd) > 1:
paste = cmd[1]
else:
paste = ''
session = requests.session()
def get_xyz(url):
response = session.get(url)
soup = bs(response.text, 'lxml')
title = soup.select('.title')[1].text
title = title.lstrip('# ').strip(' .')
podcaster = soup.select('.name')[0].text.strip().replace(' ', '')
url_clip = url.split('?')[0]
content = f'''[<strong><u>{title}</u></strong>]({url_clip} ) #podcaster/{podcaster}
#
'''
return content, title
content, title = get_xyz(url)
content_html = ''.join([f'<p>{c}</p>' for c in content.split('\n')])
if len(paste) > 0:
import richxerox
richxerox.copy(html=content_html)
notify("小宇宙👉剪贴板", title)
else:
client = flomo.Flomo(cookies=cookies)
response = client.new(content_html)
response_json = json.loads(response.text)
if response.status_code == 200:
if response_json['code'] == 0:
notify("小宇宙👉flomo", title)
else:
print(response_json)
notify("🚨 flomo Error", response_json['message'])
else:
print(response_json)
notify("🚨 flomo Failed", response_json['message'])