import panel as pn import pytz from datetime import date from datetime import datetime from dateutil.relativedelta import relativedelta, MO import param import json from functools import partial from src.search import Search_Papers def load_categories(): # f = open("categories_general.txt", "r") # list_categories = f.read().splitlines() # reading the data from the file with open('categories_arxiv.txt') as f: data = f.read() # reconstructing the data as a dictionary category_dict = json.loads(data) return category_dict def run_code(category, loaded_dict, event = None): timeframe_today = (datetime.combine(date.today(), datetime.min.time())).replace(tzinfo = pytz.utc) timeframe_week = timeframe_today + relativedelta(weekday=MO(-1)) timeframe_day = (datetime.combine(datetime(2023, 7, 16), datetime.min.time())).replace(tzinfo = pytz.utc) search_mode = "Timeframe" #Accepted values: 'NumberResults' and 'Timeframe sort_by = "PublishDate" #Accepted values: 'PublishDate', 'LastUpdatedDate' and 'Relevance' sort_order = "Descending" #Accepted values: 'Ascending' and 'Descending' query = list(loaded_dict.keys())[list(loaded_dict.values()).index(category)] search = Search_Papers(query, search_mode, timeframe_week, sort_by, sort_order) result_arxiv = search.search_arxiv() return result_arxiv def update_mainTLDR(buttons_to_add, paper_list): main_tldr = [] if buttons_to_add: table_of_contents = [] for i in range(len(buttons_to_add)): category_content = [] category_title = f"{buttons_to_add[i]}" anchor_id = category_title.lower().replace(" ", "-") # Generate anchor ID from the title table_of_contents.append(f"- [{category_title}](#{anchor_id})") for paper in paper_list[i]: # Create the HTML content for both links with line breaks html_content = ( f'{paper.entry_id}' f' - PDF' f' - {(paper.published).strftime("%d/%m/%Y %H:%M:%S")}' ) paper_content = pn.Column( pn.pane.LaTeX(f"## {paper.title}", styles={'font-size': '16pt', 'font-weight':'bold'}), # Make the title a sub-heading (H2) pn.pane.HTML(html_content, styles={'font-size': '12pt'}), pn.pane.LaTeX(paper.summary, styles={'font-size': '14pt'}), sizing_mode="scale_width" ) category_content.append(paper_content) category_column = pn.Column( pn.pane.Markdown(f"## {category_title}"), # Add a Markdown heading (H2) for the category title pn.pane.HTML(f''), # Create anchor without href pn.layout.Spacer(height=20), *category_content, pn.layout.Spacer(height=10), pn.layout.Divider(), pn.layout.Spacer(height=30), sizing_mode="scale_width" ) main_tldr.append(category_column) # Create the table of contents Markdown text toc_text = "\n".join(table_of_contents) # Insert the table of contents at the beginning of the main content main_tldr.insert(0, pn.pane.Markdown(f"## Table of Contents\n{toc_text}\n")) else: main_tldr.append(pn.pane.Markdown("# Please select some tags!")) return main_tldr