Update app.py
Browse files
app.py
CHANGED
|
@@ -53,13 +53,15 @@ def insert_sentence(text, sentence, interval):
|
|
| 53 |
|
| 54 |
def format_bibtex(paper, style='apa'):
|
| 55 |
bibtex_entry = paper["citationStyles"]["bibtex"]
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
|
| 64 |
def search_paper(query):
|
| 65 |
SEMANTIC_SCHOLAR_API_URL = "https://api.semanticscholar.org/graph/v1/paper/"
|
|
|
|
| 53 |
|
| 54 |
def format_bibtex(paper, style='apa'):
|
| 55 |
bibtex_entry = paper["citationStyles"]["bibtex"]
|
| 56 |
+
try:
|
| 57 |
+
bib_data = parse_string(bibtex_entry, 'bibtex')
|
| 58 |
+
formatter = find_plugin('pybtex.style.formatting', style)()
|
| 59 |
+
entries = list(bib_data.entries.values())
|
| 60 |
+
formatted = formatter.format_entries(entries)
|
| 61 |
+
return '\n'.join(e.text.render_as('text') for e in formatted)
|
| 62 |
+
except MissingFieldError:
|
| 63 |
+
# Fallback: ▸ return raw BibTeX ▸ or convert to a safe @misc record
|
| 64 |
+
return bibtex_entry.strip()
|
| 65 |
|
| 66 |
def search_paper(query):
|
| 67 |
SEMANTIC_SCHOLAR_API_URL = "https://api.semanticscholar.org/graph/v1/paper/"
|