mirror of
https://codeberg.org/Yael-II/ArXtic.git
synced 2026-03-15 06:16:26 +01:00
2025-09-22: Started API query, ...
This commit is contained in:
@@ -31,6 +31,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see www.gnu.org/licenses/.
|
along with this program. If not, see www.gnu.org/licenses/.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import textwrap as tw
|
||||||
import feedparser as fp
|
import feedparser as fp
|
||||||
|
|
||||||
FILTERS_DIR = os.environ.get("FILTERS_DIR")
|
FILTERS_DIR = os.environ.get("FILTERS_DIR")
|
||||||
@@ -45,9 +46,13 @@ COLOUR_INFO="\033[34m"
|
|||||||
COLOUR_WARNING="\033[93m"
|
COLOUR_WARNING="\033[93m"
|
||||||
COLOUR_ERROR="\033[91m"
|
COLOUR_ERROR="\033[91m"
|
||||||
|
|
||||||
|
def wrap(txt, length=80):
|
||||||
|
wrapped_txt = '\n'.join(tw.wrap(txt, length, break_long_words=False))
|
||||||
|
return wrapped_txt
|
||||||
|
|
||||||
def get_rss():
|
def get_rss():
|
||||||
rss = fp.parse(RSS_URL)
|
feed = fp.parse(RSS_URL)
|
||||||
return rss
|
return feed
|
||||||
|
|
||||||
def get_entries(rss):
|
def get_entries(rss):
|
||||||
entries = rss["entries"]
|
entries = rss["entries"]
|
||||||
@@ -56,17 +61,21 @@ def get_entries(rss):
|
|||||||
def print_entries(entries, fields=None):
|
def print_entries(entries, fields=None):
|
||||||
for i in range(len(entries)):
|
for i in range(len(entries)):
|
||||||
entry = entries[i]
|
entry = entries[i]
|
||||||
print(COLOUR_INFO
|
|
||||||
+ entry["id"]
|
print(COLOUR_INFO, end="")
|
||||||
+ " ("
|
print(entry["id"], end="")
|
||||||
+ entry["arxiv_announce_type"]
|
if "arxiv_announce_type" in list(entry) :
|
||||||
+ ") ["
|
print(" (" + entry["arxiv_announce_type"] + ")", end="")
|
||||||
+ entry["link"]
|
print(" [" + entry["link"] + "]", end="")
|
||||||
+ "]"
|
print(COLOUR_DEFAULT)
|
||||||
|
|
||||||
|
print(COLOUR_DEFAULT + wrap(entry["title"]) + COLOUR_DEFAULT)
|
||||||
|
print(COLOUR_OUTPUT
|
||||||
|
+ wrap(", ".join([a["name"] for a in entry["authors"]]))
|
||||||
|
+ COLOUR_DEFAULT)
|
||||||
|
print(COLOUR_INPUT
|
||||||
|
+ wrap("\n".join(entry["summary"].split("\n")[1:]))
|
||||||
+ COLOUR_DEFAULT)
|
+ COLOUR_DEFAULT)
|
||||||
print(COLOUR_DEFAULT + entry["title"] + COLOUR_DEFAULT)
|
|
||||||
print(COLOUR_OUTPUT + entry["author"] + COLOUR_DEFAULT)
|
|
||||||
print(COLOUR_INPUT + "\n".join(entry["summary"].split("\n")[1:]) + COLOUR_DEFAULT)
|
|
||||||
if fields is not None:
|
if fields is not None:
|
||||||
print(COLOUR_ERROR
|
print(COLOUR_ERROR
|
||||||
+ "Filtered field(s): "
|
+ "Filtered field(s): "
|
||||||
@@ -110,16 +119,34 @@ def filter_entries(filters, entries):
|
|||||||
filtered_fields.append([field])
|
filtered_fields.append([field])
|
||||||
added = True
|
added = True
|
||||||
elif added and value in entry[field]:
|
elif added and value in entry[field]:
|
||||||
|
if not field in filtered_fields[-1]:
|
||||||
filtered_fields[-1].append(field)
|
filtered_fields[-1].append(field)
|
||||||
return filtered_entries, filtered_fields
|
return filtered_entries, filtered_fields
|
||||||
|
|
||||||
def today_arxiv():
|
def today_arxiv():
|
||||||
filters = get_filters()
|
filters = get_filters()
|
||||||
rss = get_rss()
|
feed = get_rss()
|
||||||
entries = get_entries(rss)
|
entries = get_entries(feed)
|
||||||
entries, fields = filter_entries(filters, entries)
|
entries, fields = filter_entries(filters, entries)
|
||||||
print_entries(entries, fields)
|
print_entries(entries, fields)
|
||||||
return entries, fields
|
return entries, fields
|
||||||
|
|
||||||
today_arxiv()
|
def get_api_ids(ids):
|
||||||
|
if isinstance(ids, list) or isinstance(ids, np.ndarray):
|
||||||
|
ids = [i.replace("oai:", "").replace("arXiv.org:", "") for i in ids]
|
||||||
|
elif isinstance(ids, str):
|
||||||
|
ids = [ids.replace("oai:", "").replace("arXiv.org:", "")]
|
||||||
|
else:
|
||||||
|
raise Exception("The type of ids ({}) is not recognized".format(type(ids)))
|
||||||
|
query = QUERY_URL + "id_list=" + ",".join(ids)
|
||||||
|
feed = fp.parse(query)
|
||||||
|
return feed
|
||||||
|
|
||||||
|
"""
|
||||||
|
ids = ["oai:arXiv.org:2509.13163"]
|
||||||
|
feed = get_api_ids(ids)
|
||||||
|
entries = get_entries(feed)
|
||||||
|
print_entries(entries)
|
||||||
|
"""
|
||||||
|
|
||||||
|
today_arxiv()
|
||||||
|
|||||||
Reference in New Issue
Block a user