示例#1
0
def get_houses():
    r = requests.get("https://api.got.show/api/houses/", verify=False)
    data = json.loads(r.content)
    attr = dict.fromkeys(dir(models.House))
    api = anapioficeandfire.API()
    apihouses = []
    for x in range(1, 45):
        apihouses += api.get_houses(page=x)
    for house in data:
        values = attr.copy()
        values.update(house)
        c = models.House(name=values['name'],
                         region=values['region'],
                         words=values['words'],
                         current_lord=values['current_lord'],
                         title=values['title'],
                         overlord=values['overlord'],
                         imageLink=values['imageLink'])
        db.session.add(c)
    apinames = []
    for a in apihouses:
        apinames += [a.name]
    names = []
    for h in data:
        names += [h['name']]
    snames = set(names)
    sapinames = set(apinames)
    intersection = snames.intersection(sapinames)
    house_data = models.House.query.all()
    for ho in house_data:
        if ho.name in intersection:
            apiHo = api.get_houses(name=ho.name)[0]
            if not ho.region and apiHo.region:
                ho.region = apiHo.region
            if not ho.current_lord and apiHo.currentLord:
                req = requests.get(apiHo.currentLord)
                dat = json.loads(req.content)
                ho.current_lord = dat['name']
            if not ho.title and apiHo.titles:
                ho.title = str(apiHo.titles)
            if not ho.overlord and apiHo.overlord:
                ho.overlord = str(apiHo.overlord)
    updated_houses = models.House.query.all()
    for h in updated_houses:
        if not h.words:
            h.words = "-"
        if not h.current_lord:
            h.current_lord = "-"
        if not h.title:
            h.title = "-"
        if not h.overlord:
            h.overlord = "-"
    db.session.commit()
示例#2
0
def get_external_data(name):
    """Get book name from external storage"""
    api = anapioficeandfire.API()
    result = []
    i = 0
    run = True
    while run:
        books = api.get_books(page=i)
        run = (len(books) > 0)
        for book in books:
            if not name:
                result.append(make_output_book(book))
            elif book.name == name:
                result.append(make_output_book(book))
                run = False
                break
        i += 1
    return result
示例#3
0
 def _connect(self):
     return anapioficeandfire.API().get_characters
示例#4
0
from flask import Flask, request, jsonify
import numpy as np
import requests
import os
import anapioficeandfire
from bs4 import BeautifulSoup

app = Flask(__name__)
port = int(os.environ["PORT"])
print(port)

api = anapioficeandfire.API()


@app.route("/", methods=['POST'])
def index():

    requete = requests.get("https://jmentape.fr/")
    page = requete.content
    soup = BeautifulSoup(page, "html.parser")
    txt = str(soup.find("h1")).replace('<h1>', '').replace('</h1>', '')
    res = txt

    return jsonify(status=200, replies=[{'type': 'text', 'content': res}])


@app.route('/errors', methods=['POST'])
def errors():
    print(json.loads(request.get_data()))
    return jsonify(status=200)