File size: 3,646 Bytes
6b07340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b5c3c96
6b07340
 
de80fed
6b07340
 
 
 
 
 
 
 
 
 
d067a4a
 
7b50f30
d067a4a
 
6b07340
d067a4a
a677241
 
d35a1c3
bc0459e
a677241
 
b4ea0bc
67eae50
c59b041
b4ea0bc
fff2303
7d285fb
b4ea0bc
a1f15f9
68324b2
6889266
 
7d285fb
59b56b8
dd8468e
6889266
302e7d4
5c75ac0
4c13542
59b56b8
4e438d2
68324b2
c59b041
 
 
533b626
4c13542
 
68324b2
2ac0581
52ec4f1
97295bc
52ec4f1
f3e9607
8b374a5
 
 
c59b041
b4ea0bc
 
 
 
 
6238edb
a677241
bc0459e
a677241
7d285fb
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
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'<a href="{paper.entry_id}" target="_blank">{paper.entry_id}</a>'
                    f'  -  <a href="{paper.pdf_url}" target="_blank">PDF</a>'
                    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'<a id="{anchor_id}"></a>'),  # 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