Add a paper to the database
(paper_data: Dict)
| 715 | lookup_sql = "SELECT id FROM papers WHERE title = ?" |
| 716 | lookup_value = normalized_title |
| 717 | |
| 718 | if lookup_sql and lookup_value is not None: |
| 719 | cursor.execute(lookup_sql, (lookup_value,)) |
| 720 | row = cursor.fetchone() |
| 721 | if row: |
| 722 | return row["id"] |
| 723 | raise |
| 724 | finally: |
| 725 | conn.close() |
| 726 | |
| 727 | |
| 728 | def get_profile(user_id: str) -> Optional[Dict]: |
| 729 | """Get user profile by user_id""" |
| 730 | with connection() as conn: |
| 731 | row = conn.execute(""" |
| 732 | SELECT profile_json FROM profiles WHERE user_id = ? |
| 733 | """, (user_id,)).fetchone() |
| 734 | if row: |
| 735 | return json.loads(row["profile_json"]) |
| 736 | return None |
| 737 | |
| 738 | |
| 739 | def get_paper_by_arxiv_id(arxiv_id: str) -> Optional[Dict]: |
| 740 | """Get paper by arxiv_id""" |
| 741 | normalized_arxiv_id = _normalize_identifier(arxiv_id) |
| 742 | if not normalized_arxiv_id: |
| 743 | return None |
| 744 | with connection() as conn: |
| 745 | row = conn.execute(""" |
| 746 | SELECT * FROM papers WHERE arxiv_id = ? |
| 747 | """, (normalized_arxiv_id,)).fetchone() |
| 748 | if row: |
| 749 | return _build_paper_dict(row) |