Last active
August 28, 2024 01:08
-
-
Save 3735943886/f4340d1509a9a2913d370ffd40ae5545 to your computer and use it in GitHub Desktop.
Get Aptner Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import requests | |
import json | |
class aptner: | |
urlbase = 'https://v2.aptner.com' | |
headers = { 'Content-Type': 'application/json' } | |
token = None | |
id = None | |
password = None | |
def auth(self): | |
response = requests.post( | |
self.urlbase + '/auth/token', | |
headers = { 'Content-Type': 'application/json' }, | |
data = json.dumps({ 'id': self.id, 'password': self.password })) | |
response.raise_for_status() | |
self.token = response.json() | |
self.headers['Authorization'] = 'Bearer ' + self.token['accessToken'] | |
def get(self, getrequest): | |
response = requests.get(self.urlbase + getrequest, headers = self.headers) | |
if response.status_code == 401: | |
self.auth() | |
response = requests.get(self.urlbase + getrequest, headers = self.headers) | |
response.raise_for_status() | |
return response.json() | |
def post(self, postrequest, data): | |
if type(data) == type({}): | |
data = json.dumps(data) | |
response = requests.post(self.urlbase + postrequest, headers = self.headers, data = data) | |
if response.status_code == 401: | |
self.auth() | |
response = requests.post(self.urlbase + postrequest, headers = self.headers, data = data) | |
return response.status_code | |
아파트너 = aptner() | |
아파트너.id = '아파트너아이디' | |
아파트너.password = '아파트너암호' | |
# 관리비 내역을 표시합니다 | |
관리비 = 아파트너.get('/fee/detail') | |
print(json.dumps(관리비['fee'], indent = 2, ensure_ascii = False)) | |
# 주차를 예약합니다 | |
# visitDate는 방문날자 | |
# purpose는 방문목적 | |
# carNo는 차량번호 | |
# days는 방문기간 | |
# phone은 연락처 | |
주차예약 = { 'visitDate': '2024.09.01', 'purpose': '지인/가족방문', 'carNo': '01가1234', 'days': 1, 'phone': '01012345678' } | |
아파트너.post('/pc/reserve/', 주차예약) | |
# 주차예약상황을 표시합니다 | |
주차예약상황 = 아파트너.get('/pc/reserves') | |
print(json.dumps(주차예약상황, indent = 2, ensure_ascii = False)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment