|
| 1 | +import urllib.request |
| 2 | +import json |
| 3 | +import xml.etree.ElementTree as ET |
| 4 | +import re |
| 5 | +import os |
| 6 | + |
| 7 | +def fetch_and_update_publications(): |
| 8 | + url = 'https://dblp.org/pid/305/5359.xml' |
| 9 | + |
| 10 | + try: |
| 11 | + # Fetch the XML from DBLP |
| 12 | + response = urllib.request.urlopen(url) |
| 13 | + tree = ET.parse(response) |
| 14 | + root = tree.getroot() |
| 15 | + except Exception as e: |
| 16 | + print(f"Error fetching or parsing XML: {e}") |
| 17 | + return |
| 18 | + |
| 19 | + papers = [] |
| 20 | + |
| 21 | + # DBLP wraps each publication inside an <r> tag |
| 22 | + for r in root.findall('r'): |
| 23 | + for pub_type in ['article', 'inproceedings']: |
| 24 | + pub = r.find(pub_type) |
| 25 | + if pub is not None: |
| 26 | + |
| 27 | + # 1. Extract and Clean Authors |
| 28 | + authors = [] |
| 29 | + for author in pub.findall('author'): |
| 30 | + name = author.text |
| 31 | + # DBLP quirk: Remove trailing 4-digit disambiguation numbers (e.g., "Puneet Gupta 0002" -> "Puneet Gupta") |
| 32 | + clean_name = re.sub(r' \d{4}$', '', name) |
| 33 | + authors.append(clean_name) |
| 34 | + authors_str = ", ".join(authors) |
| 35 | + |
| 36 | + # 2. Extract Title |
| 37 | + title_node = pub.find('title') |
| 38 | + title = title_node.text if title_node is not None else "Unknown Title" |
| 39 | + |
| 40 | + # 3. Extract Year |
| 41 | + year_node = pub.find('year') |
| 42 | + year = year_node.text if year_node is not None else "Unknown Year" |
| 43 | + |
| 44 | + # 4. Extract Venue (journal for articles, booktitle for conferences) |
| 45 | + venue_node = pub.find('journal') if pub.find('journal') is not None else pub.find('booktitle') |
| 46 | + venue_text = venue_node.text if venue_node is not None else "Unknown Venue" |
| 47 | + |
| 48 | + # 5. Extract Link / DOI (<ee> tag) |
| 49 | + ee_node = pub.find('ee') |
| 50 | + ee = ee_node.text if ee_node is not None else "" |
| 51 | + |
| 52 | + papers.append({ |
| 53 | + "year": year, |
| 54 | + "authors": authors_str, |
| 55 | + "title": title, |
| 56 | + "venue": venue_text, |
| 57 | + "link": ee |
| 58 | + }) |
| 59 | + |
| 60 | + # Sort papers by year in descending order (Newest first) |
| 61 | + papers = sorted(papers, key=lambda x: str(x.get('year', '0')), reverse=True) |
| 62 | + |
| 63 | + # Ensure the _data directory exists |
| 64 | + os.makedirs('_data', exist_ok=True) |
| 65 | + |
| 66 | + # Save the cleaned data to Jekyll's _data folder |
| 67 | + output_path = os.path.join('_data', 'publications.json') |
| 68 | + with open(output_path, 'w', encoding='utf-8') as f: |
| 69 | + json.dump(papers, f, indent=4) |
| 70 | + |
| 71 | + print(f"Successfully processed and sorted {len(papers)} publications from DBLP!") |
| 72 | + |
| 73 | +if __name__ == "__main__": |
| 74 | + fetch_and_update_publications() |
0 commit comments