-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
53 lines (42 loc) · 1.29 KB
/
utils.py
File metadata and controls
53 lines (42 loc) · 1.29 KB
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
import datetime
import json
import sys
import aiosqlite
from fastapi import FastAPI, Depends, HTTPException, Request
import os
import uvicorn
from pydantic import BaseModel
from typing import List, Optional
import aiohttp
from typing import Annotated, Tuple
import requests
import sqlite3
from uuid import uuid4
import threading
import time
from hashlib import md5
from fastapi.middleware.cors import CORSMiddleware
from rss_parser import Parser
import markdownify
def link_to_md(link: str):
obj = requests.get(
f"https://api.diffbot.com/v3/article?url={link}&token=6165e93d46dfa342d862a975c813a296"
).json()
html = obj["objects"][0]["html"]
md = markdownify.markdownify(html, heading_style="ATX")
return md
def get_all_from_link(link: str):
obj = requests.get(
f"https://api.diffbot.com/v3/article?url={link}&token=6165e93d46dfa342d862a975c813a296"
).json()
return obj["objects"][0]
def detect_source_type(source: str):
if "@" in source and "get_feed" in source:
return "spile"
return "rss"
def generate_auth_token():
return str(uuid4())
def generate_content_uid(content: str | list[object]):
if isinstance(content, list):
content = " --- ".join([str(x) for x in content])
return str(md5(content.encode("utf-8")).hexdigest())