-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_client.py
64 lines (48 loc) · 2.3 KB
/
main_client.py
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
54
55
56
57
58
59
60
61
62
63
64
from retrying import retry
from gql import Client, gql
from gql.transport.aiohttp import AIOHTTPTransport
from config import ENDPOINT, STACKER_NEWS_RSS_FEED_URL
from logger import logger
from authentication_manager import AuthenticationManager
from item_manager import ItemManager
from notification_manager import NotificationManager
import os
import requests
from dotenv import load_dotenv
load_dotenv()
class StackerNewsGraphQL:
def __init__(self, endpoint=ENDPOINT):
headers = {
'Content-Type': 'application/json',
'Cookie': os.getenv("SN_AUTH_COOKIE") # Set the Cookie header
}
transport = AIOHTTPTransport(url=endpoint, headers=headers)
self.client = Client(transport=transport, fetch_schema_from_transport=False)
self.authentication_manager = AuthenticationManager(self.client)
self.item_manager = ItemManager(self.client)
self.notification_manager = NotificationManager(self.client)
def refresh_session(self):
return self.authentication_manager.refresh_session()
def get_current_session(self):
return self.authentication_manager.get_current_session()
def get_items(self, limit=10, cursor=None, sort="NEW", type=None, sub=None, name=None, when=None, by=None):
return self.item_manager.get_items(limit, cursor, sort, type, sub, name, when, by)
def search_items(self, q, sub=None, cursor=None, what=None, sort=None, when=None, limit=10):
return self.item_manager.search_items(q, sub, cursor, what, sort, when, limit)
def get_item_by_id(self, item_id):
return self.item_manager.get_item_by_id(item_id)
def check_duplicate(self, url):
return self.item_manager.check_duplicate(url)
def has_new_notifications(self):
return self.notification_manager.has_new_notifications()
def get_notifications(self, cursor=None, inc=None):
return self.notification_manager.get_notifications(cursor, inc)
def fetch_rss_feed(self):
response = requests.get(STACKER_NEWS_RSS_FEED_URL)
if response.status_code == 200:
return response.text
else:
response.raise_for_status()
def create_comment(self, parent_id, text):
return self.item_manager.create_comment(parent_id, text)
#todo: creating posts