Compare commits
2 commits
0c0822b9b9
...
949c0b9c9b
Author | SHA1 | Date | |
---|---|---|---|
|
949c0b9c9b | ||
|
5b66d9db96 |
2 changed files with 29 additions and 5 deletions
|
@ -76,6 +76,8 @@ FEED_READERS = [
|
|||
PIPYReader(name = "python3-snakes", package = "snakes",
|
||||
target = GITLAB_SNAKES_CARGAJI),
|
||||
################################ Software that I package (Forgejo) ################################
|
||||
# pdfbooklet GHReleases Averell7/PdfBooklet archpkgs/pdfbooklet
|
||||
NCAppReader(app = "pdfbooklet", project = "Averell7/PdfBooklet"),
|
||||
# meshcentral GHReleases Ylianst/MeshCentral archpkgs/meshcentral
|
||||
GithubReader(name = "meshcentral", project = "Ylianst/MeshCentral",
|
||||
target = CGJForgejoPoster("archpkgs/meshcentral")),
|
||||
|
|
|
@ -162,18 +162,40 @@ class FeedReader:
|
|||
self.name = name
|
||||
self.url = url
|
||||
self.target = target
|
||||
self.version_file = CONFIG_DIR + self.name
|
||||
self.etag_file = CONFIG_DIR + self.name + ".etag"
|
||||
self.beta_strings = [ "nightly", "beta", "alpha", "rc" ]
|
||||
|
||||
def first_item(self) -> dict[str, Any] | None:
|
||||
def first_item(self) -> dict[str, Any] | None | int:
|
||||
'''Get the first item of the feed (newest)'''
|
||||
feed = feedparser.parse(self.url)
|
||||
if os.path.isfile(self.etag_file):
|
||||
with open(self.etag_file, encoding="UTF-8") as file:
|
||||
etag = file.readline()
|
||||
else: etag = None
|
||||
feed = feedparser.parse(self.url, etag=etag)
|
||||
if feed.etag and feed.etag != etag:
|
||||
with open(self.etag_file, mode='w', encoding="UTF-8") as file:
|
||||
file.write(feed.etag)
|
||||
if feed.status == 304:
|
||||
return 304
|
||||
if len(feed.entries) == 0:
|
||||
return None
|
||||
return feed.entries[0]
|
||||
for entry in feed.entries:
|
||||
skip = False
|
||||
for beta in self.beta_strings:
|
||||
if beta in self.entry_get_version(entry)[0]:
|
||||
skip = True
|
||||
break
|
||||
if not skip:
|
||||
return entry
|
||||
return None
|
||||
|
||||
|
||||
def read_feed(self) -> bool | None:
|
||||
'''Read a feed and post an issue if a new item is found'''
|
||||
entry = self.first_item()
|
||||
if entry == 304:
|
||||
return False
|
||||
if not entry:
|
||||
return None
|
||||
version, _id = self.entry_get_version(entry)
|
||||
|
@ -192,7 +214,7 @@ class FeedReader:
|
|||
If the version is not new, or the posting fails, the method stops and returns False.'''
|
||||
# Match 1: with local file
|
||||
try:
|
||||
with open(CONFIG_DIR + self.name, encoding="utf-8") as file:
|
||||
with open(self.version_file, encoding="utf-8") as file:
|
||||
match = file.readline().strip("\n") == str(_id)
|
||||
except FileNotFoundError:
|
||||
match = False
|
||||
|
@ -206,7 +228,7 @@ class FeedReader:
|
|||
# Save to disk
|
||||
if not os.path.isdir(CONFIG_DIR):
|
||||
os.makedirs(CONFIG_DIR)
|
||||
with open(CONFIG_DIR + self.name, mode="w", encoding="utf-8") as file:
|
||||
with open(self.version_file, mode="w", encoding="utf-8") as file:
|
||||
file.write(str(_id))
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in a new issue