forked from bilimma/bsky-autoshare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
95 lines (76 loc) · 2.49 KB
/
main.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
from atproto import Client,models
import feedparser
import sqlite3
import sys
import time
import os
import re
def createdb(cur):
cur.execute('''
CREATE TABLE shared_contents (
id INTEGER PRIMARY KEY AUTOINCREMENT,
run_time TIMESTAMP,
comment TEXT,
success BOOLEAN,
context TEXT,
link TEXT
)
''')
print("Table created succesfully")
return True
def sendSkeetAndSave(cur,entry):
client = Client()
client.login(os.environ.get('BSKY_USERNAME'), os.environ.get('BSKY_PASSWORD'))
title= entry['title']
description = re.sub('<[^<]+?>', '', entry['description'])
embed_external = models.AppBskyEmbedExternal.Main(
external=models.AppBskyEmbedExternal.External(
title=title,
description=description,
uri=entry['link']
# thumb=models.blob_ref.BlobRef(
# mime_type="image/jpeg",
# size=1024,
# ref=models.blob_ref.BlobRefLink(
# link="https://www.bilimma.com/wp-content/uploads/2023/09/xcksnvm.jpg"
# )
# )
)
)
client.com.atproto.repo.create_record(
models.ComAtprotoRepoCreateRecord.Data(
repo=client.me.did,
collection=models.ids.AppBskyFeedPost,
record=models.AppBskyFeedPost.Main(
created_at=client.get_current_time_iso(),
text=title,
#facets=facets
embed=embed_external
)
)
)
print("Skeet posted!")
ressa = cur.execute("INSERT INTO shared_contents(run_time,comment,success,context,link) VALUES('"+str(run_time)+"','"+title+"',true,'"+title+"','"+link+"');")
print("Share saved!")
return True
db = sqlite3.connect('autoshare.db')
cur = db.cursor()
if(len(sys.argv)>1 and sys.argv[1] == "create-db"):
createdb(cur)
db.commit()
print("Database created successfully!")
exit()
newsFeed = feedparser.parse(os.environ.get('FEED_URL'));
entry = newsFeed.entries[1]
for entry in newsFeed.entries:
curr = cur.execute("SELECT * FROM shared_contents WHERE link='"+entry['link']+"'")
res = curr.fetchone()
print(res)
link = entry['link']
title = entry['title']
run_time = time.time()
if(res == None):
sendSkeetAndSave(cur,entry)
break
db.commit()
print("bye")