-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasictest.py
executable file
·196 lines (120 loc) · 4.38 KB
/
basictest.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/python3
''' To Do: Document this file better!!!
This is a tester/driver program for saltstaumen, a
program to monitor mastodon accounts' RSS feeds and cross post
to bluesky.
Last Revision 18 May 2024
This is the main program, the entry point, what you run on the
command line.
'''
# Main Import Block
import sys
import json
from config_feed_objsmeth import MainConfigInfo, StateConfigInfo,chk_main_state
from config_feed_objsmeth import fetch_feed
from FediQueueObjects import FirstFediQueue
from FediXbSky import BasicBlueskyQueue
from SaxeBlueSkyPython import saxeblue_cred
from SaxeBlueSkyPython.saxeblue_cred import BskyCredentials
from SaxeBlueSkyPython import bskypost_elemclass
from SaxeBlueSkyPython.bskypost_elemclass import BskyPostItem
# from SaxeBlueSkyPython import ZulkiBlueFlake
# print (sys.path)
# Configuration file setup
configfile_name = './salt-main.toml'
# Note in full production, and testing below, program gets state file
# name from main config file.
statefile_name = './salt-state.toml'
# Open the main and state config files, read, get data, and close the files
# proper handling of time formats will be needed.
# Maybe right approach to time is keeping all the stuff in the saxe
# blue library in the time format that bluesky expects, keep
# everything here in unix time, and convert as needed.
# Can be used to create a skeleton main config file if needed
# MainConfigInfo.create ('salt-main.toml', 2)
# Read the main config file
main_config = MainConfigInfo(configfile_name)
main_config.read()
# Figure out the state file name
q = main_config.state_fname()
# Can be used to create a skeleton state file
# StateConfigInfo.create (q, 2)
# Open and read state config file
state_config = StateConfigInfo(q)
state_config.read()
# state_config.print()
# Check number of RSS/Atom feeds to read
# Should be consistent across config and state files
state_config.check_feed_num()
main_config.check_feed_num()
# Use with caution; Usually only need to read the main config file
# main_config.write()
# Use this if needed to populate a new state file with the feed URLs.
# state_config.add_URLs(main_config.show_feeds())
# Update state info with feed, read, and last posted info
# reftimes = state_config.get_ref_times()
reftimes = (0,0)
state_config.update_feed_prev()
state_config.update_feed_now()
state_config.update_bsky_prev()
state_config.update_bsky_now()
# Write updated state info to the statefile
state_config.write_state()
# Get the feeds using feedparser library
feedData = []
for i in state_config.show_feeds():
feedData.append(fetch_feed(i))
# print (json.dumps(fetch_feed(i)))
# Start constructing the first of the data processing queues
fqueue_1 = FirstFediQueue (feedData)
# See how many feeds we are dealing with
ef = fqueue_1.enumerate_feeds()
# put feed items into queue
j = fqueue_1.enumerate_feed_items()
# sort items
fqueue_1.sort_entries()
#fqueue_1.print_feeds()
# fqueue_1.json_sorted_feeds()
state_config.update_entry_times(fqueue_1.sorted_feeds,j)
state_config.write_state()
fqueue_1.mark_entries4pub(reftimes)
# fqueue_1.json_marked_queue()
# Tags are not separated yet
# fqueue_1.json_sorted_feeds()
# fqueue_1.json_marked_queue()
# will need to be changed here out
Bsky_1 = BasicBlueskyQueue(fqueue_1.marked_feed_entries2pub)
# At this point, tags are sorted into tag field
# HTML is in summary and detail
Bsky_1.first_clean()
# Bsky_1.json_firstpassq()
# At this point, basic text needs more cleaning
# Do more cleaning in second pass
Bsky_1.second_clean()
# Bsky_1.json_secondpassq()
Bcred = BskyCredentials()
# print (mcfdata['BSKY_ACCOUNT'])
acct_name =main_config.config_data['BSKY_ACCOUNT']['Username']
Bcred.set_handle (acct_name)
appPass = main_config.config_data['BSKY_ACCOUNT']['App_passwd']
Bcred.get_did ()
Bcred.set_appPW (appPass)
Bcred.start_session()
sessT = Bcred.get_sessT()
# print (sessT)
myDID = Bcred.myDID()
# spq = SimplePostQueue(Bcred.echo())
# spq = SimplePostQueue(Bcred)
jj= Bsky_1.first_queue_sze()
tt = len (Bsky_1.second_pass_queue)
## jj and tt should be the same size
# check
# print ("JJ: ", jj)
# print ("tt: ", tt)
# loop through all the items queued in the second pass queue
for i in range (0,tt):
item = Bsky_1.second_queue_itm_exgest(i)
item2post = BskyPostItem(Bcred,item)
# item2post.rawentry_contents_json()
# item2post.print_basic_creds_json()
item2post.standard_workflow()