pyeasyphd 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyeasyphd might be problematic. Click here for more details.

Files changed (75) hide show
  1. pyeasyphd/.python-version +1 -1
  2. pyeasyphd/main/__init__.py +0 -4
  3. pyeasyphd/main/basic_input.py +7 -63
  4. pyeasyphd/main/python_run_md.py +3 -3
  5. pyeasyphd/main/python_run_tex.py +1 -1
  6. pyeasyphd/pyeasyphd.sublime-settings +2 -160
  7. pyeasyphd/tools/__init__.py +1 -16
  8. pyeasyphd/tools/generate/generate_from_bibs.py +54 -330
  9. pyeasyphd/tools/generate/generate_html.py +122 -0
  10. pyeasyphd/tools/generate/generate_library.py +188 -0
  11. pyeasyphd/tools/generate/generate_links.py +13 -4
  12. pyeasyphd/tools/py_run_bib_md_tex.py +12 -13
  13. pyeasyphd/tools/search/search_base.py +8 -5
  14. pyeasyphd/tools/search/search_core.py +4 -3
  15. pyeasyphd/tools/search/search_keywords.py +1 -1
  16. pyeasyphd/tools/search/search_writers.py +8 -5
  17. {pyeasyphd-0.1.0.dist-info → pyeasyphd-0.1.2.dist-info}/METADATA +3 -6
  18. pyeasyphd-0.1.2.dist-info/RECORD +27 -0
  19. pyeasyphd/bib/__init__.py +0 -1
  20. pyeasyphd/bib/bibtexbase/__init__.py +0 -7
  21. pyeasyphd/bib/bibtexbase/standardize/_base.py +0 -36
  22. pyeasyphd/bib/bibtexbase/standardize/default_data.py +0 -97
  23. pyeasyphd/bib/bibtexbase/standardize/do_on_bib.py +0 -54
  24. pyeasyphd/bib/bibtexbase/standardize/do_on_comment_block.py +0 -38
  25. pyeasyphd/bib/bibtexbase/standardize/do_on_entry_block.py +0 -310
  26. pyeasyphd/bib/bibtexbase/standardize/do_on_preamble_block.py +0 -35
  27. pyeasyphd/bib/bibtexbase/standardize/do_on_string_block.py +0 -34
  28. pyeasyphd/bib/bibtexbase/standardize_bib.py +0 -75
  29. pyeasyphd/bib/bibtexparser/__init__.py +0 -47
  30. pyeasyphd/bib/bibtexparser/bibtex_format.py +0 -87
  31. pyeasyphd/bib/bibtexparser/exceptions.py +0 -64
  32. pyeasyphd/bib/bibtexparser/library.py +0 -207
  33. pyeasyphd/bib/bibtexparser/middlewares/block/add.py +0 -94
  34. pyeasyphd/bib/bibtexparser/middlewares/block/authors.py +0 -22
  35. pyeasyphd/bib/bibtexparser/middlewares/block/doi_url.py +0 -62
  36. pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_keys_normalize.py +0 -47
  37. pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_keys_replace.py +0 -31
  38. pyeasyphd/bib/bibtexparser/middlewares/block/entry_field_values_normalize.py +0 -222
  39. pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_delete.py +0 -34
  40. pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_keep.py +0 -33
  41. pyeasyphd/bib/bibtexparser/middlewares/block/entry_fields_sort.py +0 -70
  42. pyeasyphd/bib/bibtexparser/middlewares/block/entry_types.py +0 -15
  43. pyeasyphd/bib/bibtexparser/middlewares/block/journal_booktitle.py +0 -113
  44. pyeasyphd/bib/bibtexparser/middlewares/block/month_year.py +0 -34
  45. pyeasyphd/bib/bibtexparser/middlewares/block/number_volume.py +0 -21
  46. pyeasyphd/bib/bibtexparser/middlewares/block/pages.py +0 -28
  47. pyeasyphd/bib/bibtexparser/middlewares/block/title.py +0 -20
  48. pyeasyphd/bib/bibtexparser/middlewares/library/generating_entrykeys.py +0 -98
  49. pyeasyphd/bib/bibtexparser/middlewares/library/keeping_blocks.py +0 -29
  50. pyeasyphd/bib/bibtexparser/middlewares/library/sorting_blocks.py +0 -124
  51. pyeasyphd/bib/bibtexparser/middlewares/middleware.py +0 -222
  52. pyeasyphd/bib/bibtexparser/middlewares/parsestack.py +0 -13
  53. pyeasyphd/bib/bibtexparser/middlewares/utils.py +0 -226
  54. pyeasyphd/bib/bibtexparser/middlewares_library_to_library.py +0 -414
  55. pyeasyphd/bib/bibtexparser/middlewares_library_to_str.py +0 -42
  56. pyeasyphd/bib/bibtexparser/middlewares_str_to_library.py +0 -35
  57. pyeasyphd/bib/bibtexparser/middlewares_str_to_str.py +0 -29
  58. pyeasyphd/bib/bibtexparser/model.py +0 -481
  59. pyeasyphd/bib/bibtexparser/splitter.py +0 -151
  60. pyeasyphd/bib/core/__init__.py +0 -18
  61. pyeasyphd/bib/core/convert_library_to_library.py +0 -31
  62. pyeasyphd/bib/core/convert_library_to_str.py +0 -199
  63. pyeasyphd/bib/core/convert_str_to_library.py +0 -34
  64. pyeasyphd/bib/core/convert_str_to_str.py +0 -27
  65. pyeasyphd/main/python_run_bib.py +0 -73
  66. pyeasyphd/main/python_writers.py +0 -212
  67. pyeasyphd/tools/compare/compare_bibs.py +0 -234
  68. pyeasyphd/tools/experiments_base.py +0 -203
  69. pyeasyphd/tools/format_save_bibs.py +0 -178
  70. pyeasyphd/tools/replace/replace.py +0 -81
  71. pyeasyphd/tools/spider/process_spider_bib.py +0 -247
  72. pyeasyphd/tools/spider/process_spider_url.py +0 -75
  73. pyeasyphd/tools/spider/process_spider_url_bib.py +0 -62
  74. pyeasyphd-0.1.0.dist-info/RECORD +0 -80
  75. {pyeasyphd-0.1.0.dist-info → pyeasyphd-0.1.2.dist-info}/WHEEL +0 -0
@@ -2,12 +2,12 @@ import os
2
2
  import re
3
3
  from typing import Any, Dict, List, Union
4
4
 
5
- from pyadvtools import IterateSortDict, standard_path, write_list
5
+ from pyadvtools import standard_path, write_list
6
+ from pybibtexer.tools.experiments_base import generate_standard_publisher_abbr_options_dict
6
7
 
7
- from ...bib.bibtexparser import Entry, Library
8
- from ...main import PandocMdTo, PythonRunBib, PythonWriters
9
- from ...utils.utils import html_head, html_style, html_tail, textarea_header, textarea_tail
10
- from ..experiments_base import generate_standard_publisher_abbr_options_dict
8
+ from ...main import BasicInput, PandocMdTo
9
+ from .generate_html import generate_html_content, generate_html_from_bib_data
10
+ from .generate_library import generate_library_by_filters
11
11
 
12
12
 
13
13
  def preparation(
@@ -23,12 +23,13 @@ def preparation(
23
23
 
24
24
  Examples
25
25
  --------
26
- | | current_issue | last_issue | current_month | last_month | given_month | given_months | all_months |
27
- |--------------|---------------|------------|---------------|------------|-------------|--------------|------------|
28
- | current_year | | | | | "2" | ["1", "3"] | |
29
- | given_year | "2020" | | | | | | |
30
- | given_years | ["2025"] | | | | | | |
31
- | all_years | | | | | | | |
26
+ | | current_issue | current_month | all_months |
27
+ |--------------|---------------|---------------|------------|
28
+ | current_year | YES | YES | YES |
29
+ | all_years | NO | NO | YES |
30
+ | given_years | NO | NO | YES |
31
+
32
+ given_years = ["2020", "2025"]
32
33
 
33
34
  Returns
34
35
  -------
@@ -95,12 +96,19 @@ def generate_from_bibs_and_write(
95
96
  path_storage, path_output, output_basename, pub_type, issue_or_month_flag, year_flag, options
96
97
  )
97
98
 
99
+ # Default settings
100
+ x = BasicInput(options)
101
+ options = x.options
102
+ full_json_c = x.full_json_c
103
+ full_json_j = x.full_json_j
104
+
98
105
  if generate_or_combine == "generate_data":
99
106
  publisher_abbr_dict = generate_standard_publisher_abbr_options_dict(path_storage, options)
100
107
  for publisher in publisher_abbr_dict:
101
108
  pp = os.path.join(path_output, publisher.lower())
102
109
 
103
110
  publisher_html_body = []
111
+ # Separate for abbr
104
112
  for abbr in publisher_abbr_dict[publisher]:
105
113
  print(f"*** Processing {publisher.upper()}: {abbr} ***")
106
114
  new_options = publisher_abbr_dict[publisher][abbr]
@@ -114,336 +122,52 @@ def generate_from_bibs_and_write(
114
122
  path_abbr = os.path.join(root, files[0])
115
123
 
116
124
  # Generate and process library
117
- library = generate_given_library(path_abbr, issue_or_month_flag, year_flag, new_options)
125
+ library = generate_library_by_filters(
126
+ path_abbr, issue_or_month_flag, year_flag, new_options, full_json_c, full_json_j
127
+ )
118
128
 
119
129
  # Generate md, tex, pdf, html
120
- html_body = generate_md_tex_pdf_html(abbr, library, pp, new_options)
130
+ html_body = generate_html_from_bib_data(abbr, library, pp, new_options, full_json_c, full_json_j)
121
131
  if combine_flag and html_body:
122
132
  publisher_html_body.extend(html_body + ["\n"])
123
133
 
124
134
  # Combine for publisher
125
135
  if publisher_html_body:
126
- html_content = _html_content(publisher_html_body[:-1], publisher)
136
+ html_content = generate_html_content(publisher_html_body[:-1], publisher)
127
137
  write_list(html_content, f"{publisher}_all.html", "w", pp, False)
128
138
 
129
139
  elif generate_or_combine == "combine_data":
130
- # Compulsory
131
- options["include_abbr_list"] = []
132
- options["exclude_abbr_list"] = []
133
- publisher_abbr_dict = generate_standard_publisher_abbr_options_dict(path_storage, options)
134
- for publisher in publisher_abbr_dict:
135
- print(f"*** Combining papers for {publisher.upper()} ***")
136
- pp = os.path.join(path_output, publisher.lower())
137
- absolute_path = os.path.join(path_root, publisher) if len(path_root) > 0 else ""
140
+ _combine_data(path_storage, path_root, path_output, combine_flag, options)
138
141
 
139
- link = [f"# {publisher.upper()}\n\n"]
140
- for abbr in publisher_abbr_dict[publisher]:
141
- if os.path.exists(os.path.join(pp, abbr, f"{abbr}.html")):
142
- ll = os.path.join(absolute_path, abbr, f"{abbr}.html")
143
- link.append(f"- [{abbr}]({ll})\n")
144
-
145
- if combine_flag:
146
- ll = os.path.join(absolute_path, f"{publisher}_all.html")
147
- link.insert(1, f"- [All Journals]({ll})\n")
148
-
149
- # Process combined content
150
- if len(link) > 1:
151
- write_list(link, f"{publisher}_link.md", "w", pp, False)
152
- PandocMdTo({}).pandoc_md_to_html(pp, pp, f"{publisher}_link.md", f"{publisher}_link.html", True)
153
-
154
- # Clean up
155
- for name in ["_link"]:
156
- if os.path.exists(file := os.path.join(pp, f"{publisher}{name}.md")):
157
- os.remove(file)
158
142
  return None
159
143
 
160
144
 
161
- def generate_given_library(
162
- original_data: Union[List[str], str, Library],
163
- issue_or_month_flag: Union[str, List[str]],
164
- year_flag: Union[str, List[str]] = "current_year",
165
- options: Dict[str, Any] = {},
166
- ) -> Library:
167
- """Generate a Library object from input data with given filters.
168
-
169
- Parameters
170
- ----------
171
- original_data : Union[List[str], str, Library]
172
- Input bibliography data
173
- issue_or_month_flag : Union[str, List[str]]
174
- Flag for issue/month selection
175
- year_flag : Union[str, List[str]], optional
176
- Flag for year selection, by default "current_year"
177
- options : Dict[str, Any], optional
178
- Additional options, by default {}
179
-
180
- Returns
181
- -------
182
- Library
183
- Processed library object
184
- """
185
- _options = {}
186
- # convert_str_to_library
187
- _options["is_standardize_bib"] = False # default is True
188
- # middlewares_str_to_library.py
189
- _options["is_display_implicit_comments"] = False # default is True
190
-
191
- # convert_library_to_library.py
192
- _options["choose_abbr_zotero_save"] = "save" # default is "save"
193
- # middlewares_library_to_library.py
194
- _options["generate_entry_cite_keys"] = False # default is False
195
- _options["function_common_again"] = False # default is True
196
- _options["function_common_again_abbr"] = False # default is True
197
- _options["function_common_again_zotero"] = False # default is True
198
- _options["function_common_again_save"] = False # default is True
199
-
200
- # convert_library_to_str.py
201
- # middlewares_library_to_str.py
202
- _options["is_sort_entry_fields"] = True # compulsory
203
- _options["is_sort_blocks"] = True # compulsory
204
- _options["sort_entries_by_field_keys_reverse"] = True # compulsory
205
-
206
- # convert_str_to_str.py
207
- _options["default_additional_field_list"] = []
208
- # middlewares_str_to_str.py
209
- _options["substitute_in_bib"] = False # default is True
210
-
211
- _options.update(options)
212
- _python_bib = PythonRunBib(_options)
213
-
214
- # Generate nested entries dictionary
215
- entry_type_year_volume_number_month_entry_dict = _python_bib.parse_to_nested_entries_dict(original_data)
216
- old_dict = entry_type_year_volume_number_month_entry_dict
217
-
218
- # Filter by year_flag
219
- new_dict = {}
220
- for entry_type in old_dict:
221
- years = [year for year in old_dict[entry_type]]
222
-
223
- # Update years
224
- if isinstance(year_flag, List):
225
- years = sorted(list(set(years).intersection(set(year_flag))))
226
- elif year_flag.lower().strip() == "all_years":
227
- years = years
228
- elif year_flag.lower().strip() == "current_year":
229
- years = years[:1]
230
- else:
231
- if year_flag not in years:
232
- continue
233
- else:
234
- years = [year_flag]
235
-
236
- for year in years:
237
- new_dict.setdefault(entry_type, {}).update({year: old_dict[entry_type][year]})
238
-
239
- # Filter by issue/month flag
240
- if issue_or_month_flag in ["current_issue", "last_issue"]:
241
- return obtain_issue_flag_library(new_dict, issue_or_month_flag)
242
-
243
- return obtain_month_flag_library(new_dict, issue_or_month_flag)
244
-
245
-
246
- def obtain_issue_flag_library(
247
- old_dict: Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, List[Entry]]]]]], issue_flag: str = "current_issue"
248
- ) -> Library:
249
- """Filter library by issue flag."""
250
- old_dict = IterateSortDict(True).dict_update(old_dict)
251
-
252
- entries = []
253
- for entry_type in old_dict:
254
- for year in old_dict[entry_type]:
255
- temp_dict = old_dict[entry_type][year]
256
-
257
- # Article entries
258
- if entry_type.lower() == "article":
259
- volumes, numbers, months = [], [], []
260
- for volume in (volumes := [volume for volume in temp_dict]):
261
- for number in (numbers := [number for number in temp_dict[volume]]):
262
- months = [month for month in temp_dict[volume][number]]
263
- break
264
- break
265
-
266
- if issue_flag == "current_issue": # current volume, current issue, and current month
267
- entries.extend(temp_dict[volumes[0]][numbers[0]][months[0]])
268
-
269
- elif issue_flag == "last_issue":
270
- # Logic for getting previous issue
271
- if len(months) == 1:
272
- if len(numbers) == 1:
273
- if len(volumes) == 1:
274
- entries.extend(temp_dict[volumes[0]][numbers[0]][months[0]])
275
- else:
276
- numbers = [number for number in temp_dict[volumes[1]]]
277
- months = [month for month in temp_dict[volumes[1]][numbers[0]]]
278
- entries.extend(temp_dict[volumes[1]][numbers[0]][months[0]])
279
- else:
280
- months = [month for month in temp_dict[volumes[0]][numbers[1]]]
281
- entries.extend(temp_dict[volumes[0]][numbers[1]][months[0]])
282
- else:
283
- entries.extend(temp_dict[volumes[0]][numbers[0]][months[1]])
284
-
285
- else:
286
- print(f"Unknown issue flag: {issue_flag}.")
287
-
288
- else:
289
- # Non-article entries
290
- for volume in temp_dict:
291
- for number in temp_dict[volume]:
292
- for month in temp_dict[volume][number]:
293
- entries.extend(temp_dict[volume][number][month])
294
-
295
- return Library(entries)
296
-
297
-
298
- def obtain_month_flag_library(
299
- old_dict: Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, List[Entry]]]]]],
300
- month_flag: Union[str, List[str]] = "current_month",
301
- ) -> Library:
302
- """Filter library by month flag."""
303
- new_dict = {}
304
- for entry_type in old_dict:
305
- for year in old_dict[entry_type]:
306
-
307
- for volume in old_dict[entry_type][year]:
308
- for number in old_dict[entry_type][year][volume]:
309
- for month in old_dict[entry_type][year][volume][number]:
310
- new_dict.setdefault(entry_type, {}).setdefault(year, {}).setdefault(month, {}).setdefault(
311
- volume, {}
312
- ).setdefault(number, []).extend(old_dict[entry_type][year][volume][number][month])
313
-
314
- # Sort
315
- old_dict = IterateSortDict(True).dict_update(new_dict)
316
-
317
- entries = []
318
- for entry_type in old_dict:
319
- for year in old_dict[entry_type]:
320
- temp_dict = old_dict[entry_type][year]
321
- default_months = [month for month in temp_dict]
322
-
323
- # Update month
324
- new_months = []
325
- if month_flag == "current_month": # current_month
326
- new_months = [default_months[0]]
327
- elif month_flag == "last_month": # last_month
328
- new_months = [default_months[1]] if len(default_months) > 1 else []
329
- elif month_flag == "all_months": # all months
330
- new_months = default_months
331
- else:
332
- if isinstance(month_flag, str): # given month
333
- if month_flag in default_months:
334
- new_months = [month_flag]
335
- else:
336
- for month in month_flag: # given months
337
- if month in default_months:
338
- new_months.append(month)
339
-
340
- for month in new_months:
341
- for volume in temp_dict[month]:
342
- for number in temp_dict[month][volume]:
343
- entries.extend(temp_dict[month][volume][number])
344
-
345
- return Library(entries)
346
-
347
-
348
- def generate_md_tex_pdf_html(
349
- abbr_standard: str,
350
- original_bib_data: Union[List[str], str, Library],
351
- path_output: str,
352
- options: Dict[str, Any] = {},
353
- ) -> List[str]:
354
- """Generate markdown and LaTeX from bibliography data."""
355
- options_: dict = {
356
- # convert_str_to_library
357
- "is_standardize_bib": False,
358
- # middlewares_str_to_library.py
359
- "is_display_implicit_comments": False,
360
- #
361
- # convert_library_to_library.py
362
- # middlewares_library_to_library.py
363
- "function_common_again": False,
364
- "function_common_again_abbr": False,
365
- "function_common_again_zotero": False,
366
- "function_common_again_save": False,
367
- "abbr_index_article_for_abbr": 2,
368
- "abbr_index_inproceedings_for_abbr": 2,
369
- #
370
- # convert_library_to_str.py
371
- "empty_entry_cite_keys": True,
372
- # middlewares_library_to_str.py
373
- "is_sort_entry_fields": True,
374
- "is_sort_blocks": True,
375
- "sort_entries_by_field_keys_reverse": True,
376
- }
377
- options_.update(options)
378
-
379
- # Process bibliography data
380
- _python_bib = PythonRunBib(options_)
381
- _, zotero_library, _ = _python_bib.parse_to_multi_standard_library(original_bib_data)
382
-
383
- _python_writer = PythonWriters(options_)
384
-
385
- # Generate HTML content body
386
- html_body = []
387
- for entry in zotero_library.entries:
388
- html_body.append(_format_entry(entry, abbr_standard, _python_writer.write_to_str([entry])))
389
-
390
- if len(html_body) > 0:
391
- html_body = (
392
- [f'<h2 id="{abbr_standard.lower()}">{abbr_standard} - {len(zotero_library.entries)}</h2>\n', "<ul>\n"]
393
- + html_body
394
- + ["</ul>\n"]
395
- )
396
-
397
- html_content = _html_content(html_body, abbr_standard)
398
-
399
- # Write output file
400
- write_list(html_content, f"{abbr_standard}.html", "w", os.path.join(path_output, abbr_standard), False)
401
-
402
- return html_body
403
-
404
-
405
- def _html_content(html_body, abbr_standard):
406
- html_content = [html_head.format(abbr_standard), html_style, "\n"]
407
- html_content.extend(html_body)
408
- html_content.extend([html_tail])
409
- return html_content
410
-
411
-
412
- def _format_entry(entry, abbr, data_list):
413
- """Format a single bibliography entry into HTML."""
414
- number = entry["number"] if "number" in entry else ""
415
- pages = entry["pages"] if "pages" in entry else ""
416
- title = entry["title"] if "title" in entry else ""
417
- year = entry["year"] if "year" in entry else ""
418
- volume = entry["volume"] if "volume" in entry else ""
419
-
420
- url = ""
421
- if "doi" in entry:
422
- doi = entry["doi"]
423
- url = doi if doi.startswith("http") else f"https://doi.org/{doi}"
424
- elif "url" in entry:
425
- url = entry["url"]
426
-
427
- line = _format_entry_apa(title, year, volume, number, pages, url, abbr)
428
-
429
- line = f"<li><details>\n<summary>\n{line.strip()}\n</summary>\n"
430
-
431
- return line + textarea_header + "".join(data_list).rstrip() + textarea_tail + "\n</details></li>\n"
432
-
433
-
434
- def _format_entry_apa(title, year, volume, number, pages, url, abbr):
435
- line = f"({year}). {title}. <em>{abbr}</em>"
436
- if volume:
437
- line += f", <em>{volume}</em>"
438
- if number:
439
- line += f"({number})"
440
-
441
- if pages:
442
- line += f", {pages}"
443
-
444
- line += "."
445
-
446
- if url:
447
- line += f" (<a href='{url}'>www</a>)"
448
-
449
- return line
145
+ def _combine_data(path_storage, path_root, path_output, combine_flag, options):
146
+ # Compulsory
147
+ options["include_abbr_list"] = []
148
+ options["exclude_abbr_list"] = []
149
+ publisher_abbr_dict = generate_standard_publisher_abbr_options_dict(path_storage, options)
150
+ for publisher in publisher_abbr_dict:
151
+ print(f"*** Combining papers for {publisher.upper()} ***")
152
+ pp = os.path.join(path_output, publisher.lower())
153
+ absolute_path = os.path.join(path_root, publisher) if len(path_root) > 0 else ""
154
+
155
+ link = [f"# {publisher.upper()}\n\n"]
156
+ for abbr in publisher_abbr_dict[publisher]:
157
+ if os.path.exists(os.path.join(pp, abbr, f"{abbr}.html")):
158
+ ll = os.path.join(absolute_path, abbr, f"{abbr}.html")
159
+ link.append(f"- [{abbr}]({ll})\n")
160
+
161
+ if combine_flag:
162
+ ll = os.path.join(absolute_path, f"{publisher}_all.html")
163
+ link.insert(1, f"- [All Journals]({ll})\n")
164
+
165
+ # Process combined content
166
+ if len(link) > 1:
167
+ write_list(link, f"{publisher}_link.md", "w", pp, False)
168
+ PandocMdTo({}).pandoc_md_to_html(pp, pp, f"{publisher}_link.md", f"{publisher}_link.html", True)
169
+
170
+ # Clean up
171
+ for name in ["_link"]:
172
+ if os.path.exists(file := os.path.join(pp, f"{publisher}{name}.md")):
173
+ os.remove(file)
@@ -0,0 +1,122 @@
1
+ import os
2
+ from typing import Any, Dict, List, Union
3
+
4
+ from pyadvtools import write_list
5
+ from pybibtexer.bib.bibtexparser import Library
6
+ from pybibtexer.main import PythonRunBib, PythonWriters
7
+
8
+ from ...utils.utils import html_head, html_style, html_tail, textarea_header, textarea_tail
9
+
10
+
11
+ def generate_html_content(html_body, abbr_standard):
12
+ """Create complete HTML document from body content."""
13
+ return [html_head.format(abbr_standard), html_style, "\n"] + html_body + [html_tail]
14
+
15
+
16
+ def generate_html_from_bib_data(
17
+ abbr_standard: str,
18
+ original_bib_data: Union[List[str], str, Library],
19
+ path_output: str,
20
+ options: Dict[str, Any] = {},
21
+ full_json_c: str = "",
22
+ full_json_j: str = ""
23
+ ) -> List[str]:
24
+ """Generate html from bibliography data."""
25
+ # Set processing options
26
+ processing_options: dict = {
27
+ # convert_str_to_library
28
+ "is_standardize_bib": False,
29
+ # middlewares_str_to_library.py
30
+ "is_display_implicit_comments": False,
31
+ #
32
+ # convert_library_to_library.py
33
+ # middlewares_library_to_library.py
34
+ "function_common_again": False,
35
+ "function_common_again_abbr": False,
36
+ "function_common_again_zotero": False,
37
+ "function_common_again_save": False,
38
+ "abbr_index_article_for_abbr": 2,
39
+ "abbr_index_inproceedings_for_abbr": 2,
40
+ #
41
+ # convert_library_to_str.py
42
+ "empty_entry_cite_keys": True,
43
+ # middlewares_library_to_str.py
44
+ "is_sort_entry_fields": True,
45
+ "is_sort_blocks": True,
46
+ "sort_entries_by_field_keys_reverse": True,
47
+ }
48
+ # Update with provided options
49
+ processing_options.update(options)
50
+
51
+ # Process bibliography data
52
+ _python_bib = PythonRunBib(full_json_c, full_json_j, processing_options)
53
+ _, zotero_library, _ = _python_bib.parse_to_multi_standard_library(original_bib_data)
54
+
55
+ _python_writer = PythonWriters(full_json_c, full_json_j, processing_options)
56
+
57
+ # Generate HTML content for each entry
58
+ html_body = []
59
+ for entry in zotero_library.entries:
60
+ html_body.append(_format_entry_to_html(entry, abbr_standard, _python_writer.write_to_str([entry])))
61
+
62
+ # Create complete HTML document if entries exist
63
+ if len(html_body) > 0:
64
+ html_body = (
65
+ [f'<h2 id="{abbr_standard.lower()}">{abbr_standard} - {len(zotero_library.entries)}</h2>\n', "<ul>\n"]
66
+ + html_body
67
+ + ["</ul>\n"]
68
+ )
69
+
70
+ html_content = generate_html_content(html_body, abbr_standard)
71
+ output_dir = os.path.join(path_output, abbr_standard)
72
+
73
+ # Write output file
74
+ write_list(html_content, f"{abbr_standard}.html", "w", output_dir, False)
75
+
76
+ return html_body
77
+
78
+
79
+ def _format_entry_to_html(entry, abbr, data_list):
80
+ """Format a single bibliography entry into HTML."""
81
+ # Extract entry fields
82
+ number = entry["number"] if "number" in entry else ""
83
+ pages = entry["pages"] if "pages" in entry else ""
84
+ title = entry["title"] if "title" in entry else ""
85
+ year = entry["year"] if "year" in entry else ""
86
+ volume = entry["volume"] if "volume" in entry else ""
87
+
88
+ # Get URL (DOI preferred, fall back to URL)
89
+ url = ""
90
+ if "doi" in entry:
91
+ doi = entry["doi"]
92
+ url = doi if doi.startswith("http") else f"https://doi.org/{doi}"
93
+ elif "url" in entry:
94
+ url = entry["url"]
95
+
96
+ # Format entry in APA style
97
+ line = _format_entry_to_apa_style(title, year, volume, number, pages, url, abbr)
98
+
99
+ line = f"<li><details>\n<summary>\n{line.strip()}\n</summary>\n"
100
+
101
+ # Create HTML structure with details
102
+ return line + textarea_header + "".join(data_list).rstrip() + textarea_tail + "\n</details></li>\n"
103
+
104
+
105
+ def _format_entry_to_apa_style(title, year, volume, number, pages, url, abbr):
106
+ """Format entry in APA citation style."""
107
+ line = f"({year}). {title}. <em>{abbr}</em>"
108
+
109
+ if volume:
110
+ line += f", <em>{volume}</em>"
111
+ if number:
112
+ line += f"({number})"
113
+
114
+ if pages:
115
+ line += f", {pages}"
116
+
117
+ line += "."
118
+
119
+ if url:
120
+ line += f" (<a href='{url}'>www</a>)"
121
+
122
+ return line