-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathschema.py
More file actions
53 lines (40 loc) · 1.18 KB
/
schema.py
File metadata and controls
53 lines (40 loc) · 1.18 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
from graphene import ObjectType, String, Boolean, ID, List, Field, Int
from airbnb import Api
import json
import os
from collections import namedtuple
def _json_object_hook(d):
return namedtuple('X', d.keys())(*d.values())
def json2obj(data):
return json.loads(data, object_hook=_json_object_hook)
class User(ObjectType):
first_name = String()
has_profile_pic = Boolean()
id = ID()
picture_url = String()
smart_name = String()
thumbnail_url = String()
class Listing(ObjectType):
id = ID()
name = String()
class Review(ObjectType):
author = Field(User)
author_id = ID()
can_be_edited = Boolean()
comments = String()
created_at = String()
id = Int()
language = String()
listing = Field(Listing)
listing_id = ID()
recipient = Field(User)
recipient_id = ID()
response = String()
role = String()
user_flag = Boolean()
class Query(ObjectType):
reviews = List(Review, id=Int(required=True))
def resolve_reviews(self, info, id):
api = Api(os.environ.get("AIRBNB_LOGIN"),
os.environ.get("AIRBNB_PASSWORD"))
return json2obj(json.dumps(api.get_reviews(id)["reviews"]))