Пример #1
0
Файл: main.py Проект: xeust/yarc
from deta import App
from fastapi import FastAPI
from fastapi import FastAPI, Response
from fastapi.responses import HTMLResponse
from pydantic import BaseModel
from jinja2 import Template
from note import *


fast = FastAPI()

app = App(fast)


@app.get("/")
def html_handler():
    home_template = Template((open("index.html").read()))
    home_css = open("style.css").read()
    home_hyper = open("home.js").read()
    return HTMLResponse(home_template.render(home_js=home_hyper, base_url=base_url, css=home_css))


@app.get("/search/{search_term}")
def search_handler(search_term: str):
    return fetch_notes(search_term)


#create notes or update backlinks server side if diff in links
@app.get("/notes/{note_name}")
async def read_note(note_name: str, json: bool = False):
    note = get_note(note_name)
Пример #2
0
import json
import os
import random
from deta import App, Deta
from dotenv import load_dotenv
from fastapi import FastAPI

load_dotenv('env')

app = App(FastAPI())
deta = Deta(os.environ.get('PROJECT_KEY'))
db = deta.Base('quotes')

db_appends = {
    'posted_facebook_at': 'NULL',
    'posted_telegram_at': 'NULL',
    'posted_twitter_at': 'NULL',
}


def db_get_quotes(query):
    return list(db.fetch(query))[0]


def db_cleanup_quotes(quotes):
    for quote in quotes:
        for k in db_appends.keys():
            quote.pop(k, None)
    return quotes

Пример #3
0
from flask import Flask, jsonify
from bs4 import BeautifulSoup
from deta import App
import requests
import json

app = App(Flask(__name__))


def get_body(article_url):  # pure function
    resp = requests.get(article_url)
    src = BeautifulSoup(resp.text, features="html.parser")
    for table in src.font.find_all('table'):
        table.decompose()
    return src.font


@app.route("/posts")
def home():
    titles = json.load(open("titles.json", "r"))
    res = jsonify(titles)
    res.headers.add('Access-Control-Allow-Origin', '*')
    return res


@app.route("/posts/<id>")
def post(id):
    posts = json.load(open("posts.json", "r"))

    try:
        res = jsonify(
Пример #4
0
from datetime import datetime
import logging
import os
import re
import requests
from deta import App
from deta import Deta
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

deta = Deta()
app = App(FastAPI())
db = deta.Base("admetsar2")
emaildb = deta.Base("emails")
origins = ["http://*****:*****@zealseeker.com'
Пример #5
0
from typing import Any, Dict, Optional
import requests
import pytz
import os
from datetime import date, datetime
from deta import App  #comment this when you're developing locally

app = App()  #comment this when you're developing locally

token: str = os.getenv('TOKEN')
chat_id: str = os.getenv('CHAT_ID')


def sendTGMessage(message: str) -> None:
    url = f'https://api.telegram.org/bot{token}/sendMessage'
    msg_data = {'chat_id': chat_id, 'text': message, "parse_mode": "Markdown"}
    resp = requests.post(url, msg_data).json()
    print(
        "Message Not Send" if resp['ok'] is False else "👉    Message Sent")


@app.lib.cron()  #comment this when you're developing locally
def getCowinData(event: Optional[str] = None) -> None:
    tz = pytz.timezone("Asia/Calcutta")
    time = datetime.now(tz).strftime('%H:%M:%S')
    tdate = date.today().strftime("%d-%m-%Y")
    data = requests.get(
        f"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=304&date={tdate}"
    ).json()
    nos_centers = len(data['centers'])
    print(nos_centers)
Пример #6
0
from deta import App, Deta
from fastapi import FastAPI, Request, responses
from fastapi.staticfiles import StaticFiles

deta = Deta()
db = deta.Base("people")  # init the DB

# We are wrapping FastAPI with a Deta wrapper to be able to use `deta run`
# See line 31. It's optional.
app = App(FastAPI())
app.mount("/static", StaticFiles(directory="static"), name="static")


@app.get("/")
def index():
    return responses.HTMLResponse(open("./index.html").read())


@app.post("/data")
async def post(r: Request):
    items = await r.json()
    for item in items:
        db.put(item)
    return item


@app.get("/data")
async def get():
    return next(db.fetch())

Пример #7
0
import nltk
import os
from deta import App, Deta
from flask import Flask
from words import words
from nltk.stem import LancasterStemmer, SnowballStemmer

app = App(Flask(__name__))

sno = SnowballStemmer('english')
lan = LancasterStemmer()

proj_key = os.environ["PROJ_KEY"]
deta = Deta(proj_key)
reverse_stems = deta.Base("lancaster_stems")


def reversestemmer(word, stemmer):
    variants = []
    stem = stemmer.stem(word)

    for each in words:
        if stemmer.stem(each) == stem:
            variants.append(each)

    return {"key": stem, "stem": stem, "words": variants}


def formatted(stem_dict, word):
    return_words = stem_dict
    del return_words["key"]