-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_wrapper.py
More file actions
78 lines (65 loc) · 2.32 KB
/
api_wrapper.py
File metadata and controls
78 lines (65 loc) · 2.32 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import json
import logging
import urllib
import requests
import os
from instagrapi import Client
from instagrapi.types import Usertag
from pathlib import Path
def get_meals(date: str):
api_key = os.getenv("API_KEY")
ofcdc = os.getenv("OFCDC_CODE")
school = os.getenv("SCHOOL_CODE")
base_url = "https://open.neis.go.kr/hub/mealServiceDietInfo"
args = {
"KEY": api_key,
"Type": "json",
"ATPT_OFCDC_SC_CODE": ofcdc,
"SD_SCHUL_CODE": school,
"MLSV_YMD": date,
}
url = base_url + "?" + urllib.parse.urlencode(args)
response = requests.get(url)
return json.loads(response.text)["mealServiceDietInfo"][1]["row"] # TODO 급식 메뉴 없을때
def upload_post(locations: list, description: str):
logger = logging.getLogger(__name__)
username = os.getenv("INSTAGRAM_USERNAME")
password = os.getenv("INSTAGRAM_PASSWORD")
author = os.getenv("INSTAGRAM_AUTHOR")
client = Client()
if os.path.exists("session.json"):
client.load_settings("session.json")
client.login(username, password)
else:
client.login(username, password)
client.dump_settings("session.json")
extra_data = {}
usertags = []
if author:
users = client.search_following(str(client.user_id), author)
if len(users) > 0:
usertags.append(Usertag(user=users[0], x=0.5, y=0.5))
extra_data["invite_coauthor_user_id"] = users[0].pk
else:
logger.info(f"User @{author} not found")
if len(locations) == 1:
client.photo_upload(locations[0], description, extra_data=extra_data)
else:
client.album_upload([Path(location) for location in locations], description,
usertags=usertags, extra_data=extra_data)
def upload_story(location: str):
username = os.getenv("INSTAGRAM_USERNAME")
password = os.getenv("INSTAGRAM_PASSWORD")
client = Client()
if os.path.exists("session.json"):
client.load_settings("session.json")
client.login(username, password)
else:
client.login(username, password)
client.dump_settings("session.json")
client.photo_upload_to_story(Path(location))
if __name__ == "__main__":
from dotenv import load_dotenv
import pprint
load_dotenv()
pprint.pprint(get_meals("20250821"))