File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from loading_api_wrapper .api import LoadingApiWrapper
Original file line number Diff line number Diff line change 1+ import requests
2+
3+ API_URL = "https://api.loading.se"
4+ API_VERSION = "v1"
5+ USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
6+
7+
8+ class LoadingApiWrapper :
9+ def __init__ (self , email = None , password = None ):
10+ self .cookies = None
11+
12+ if email and password :
13+ response = self ._authenticate (email , password )
14+
15+ if response .get ("code" ) == 200 :
16+ self .cookies = response .get ("cookies" )
17+
18+ def _authenticate (self , email , password ):
19+ url = f"{ API_URL } /{ API_VERSION } /auth/login"
20+ headers = {
21+ "User-Agent" : USER_AGENT ,
22+ "content-type" : "application/x-www-form-urlencoded" ,
23+ }
24+ data = {
25+ "email" : email ,
26+ "password" : password ,
27+ }
28+ response = requests .post (url , headers = headers , data = data )
29+
30+ if response .status_code == 200 :
31+ return {"code" : 200 , "cookies" : response .cookies }
32+
33+ return response .json ()
You can’t perform that action at this time.
0 commit comments