-
Notifications
You must be signed in to change notification settings - Fork 0
/
FediQueueObjects.py
108 lines (82 loc) · 2.8 KB
/
FediQueueObjects.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
import copy
import json
from operator import attrgetter
from FediEntryObjects import check_entry2pub
''' Feed Queues'''
class FirstFediQueue:
''' tbd'''
def __init__(self, feedset):
self.feeds = feedset
self.num_feeds = None
self.num_entries_feed = []
self.sorted_feeds = copy.deepcopy(feedset)
self.marked_feed_entries2pub = []
def print_feeds (self):
''' print my feeds'''
print (self.feeds)
return
def print_sorted_feeds (self):
''' print my feeds'''
print (self.feeds)
return
def json_feeds(self):
''' print feeds as json'''
print (json.dumps(self.feeds))
return
def json_sorted_feeds(self):
''' print feeds as json'''
print (json.dumps(self.sorted_feeds))
return
def json_marked_queue(self):
''' print marked feed'''
print (json.dumps(self.marked_feed_entries2pub))
return
def enumerate_feeds (self):
''' count number of feeds'''
num_feeds = len (self.feeds)
self.num_feeds = num_feeds
return num_feeds
def enumerate_feed_items (self):
'''Describe how many entries are in each feed'''
feeds = self.num_feeds
for i in range (0, feeds):
# print (self.feeds[i]['entries'])
# len (self.feeds[i]['entries'])
num_entries_feed = len (self.feeds[i]['entries'])
self.num_entries_feed.append(num_entries_feed)
return self.num_entries_feed
def sort_entries (self):
'''sort feeds, one at a time
'''
fl = self.num_feeds
for i in range (0,fl):
sorted_f = \
sorted(self.feeds[i]['entries'], reverse = True, \
key=attrgetter('published_parsed'))
self.sorted_feeds.append(sorted_f)
# End for loop
#self.sorted_feeds = sorted_feeds_by_time
return self.sorted_feeds
def mark_entries4pub (self,reftimes):
'''docstring mark for pub, put into unified queue
'''
pblsh_F = {
'PutEntryInQueue': bool(False)
}
pblsh_T = {
'PutEntryInQueue': bool(True)
}
fl = self.num_feeds
nef = self.num_entries_feed
for i in range (0,fl):
for j in range (0,nef[i]):
fedientry = self.sorted_feeds[i]['entries'][j]
if check_entry2pub(fedientry,reftimes[i]) == bool (True):
fedientry.update(pblsh_T)
self.marked_feed_entries2pub.append(fedientry)
elif check_entry2pub(fedientry,reftimes[i]) == bool(False):
fedientry.update(pblsh_F)
# End If
# end inner loop
# End outer loop
return