Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (28 sloc) 930 Bytes
"""
GraphQL schema for extracting results from a website.
"""
import graphene
import extraction
import requests
def extract(url):
html = requests.get(url).text
extracted = extraction.Extractor().extract(html, source_url=url)
print(extracted)
return extracted
class Website(graphene.ObjectType):
url = graphene.String(required=True)
title = graphene.String()
description = graphene.String()
image = graphene.String()
feed = graphene.String()
class Query(graphene.ObjectType):
website = graphene.Field(Website, url=graphene.String())
def resolve_website(self, info, url):
extracted = extract(url)
return Website(url=url,
title=extracted.title,
description=extracted.description,
image=extracted.image,
feed=extracted.feed
)
schema = graphene.Schema(query=Query)