Skip to content

Commit

Permalink
Add code
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelNLP committed Mar 17, 2024
1 parent 9ca51e0 commit c1c97ae
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,4 @@ pip-selfcheck.json

# End of https://www.gitignore.io/api/test,python,pycharm+all,jupyternotebook
/test_report.xml
/data/*
45 changes: 45 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json

import requests
from datetime import datetime
import urllib.request


with open("data/cookies.json") as cookies_json:
cookies = json.load(cookies_json)

with open("data/headers.json") as headers_json:
headers = json.load(headers_json)

counter = 0
page = 0

while page < 5:
response = requests.get(
"https://app.childdiary.net/api/media",
params={"page": str(page)},
cookies=cookies,
headers=headers,
)

if response.status_code != 200 or response.text == "[]":
break

a = response.json()

for media in response.json():
date = datetime.strptime(media["CreatedOn"], "%Y-%m-%dT%H:%M:%S.%fZ").date()

if media["Type"] == "image/jpeg":
image_data = requests.get(media["Url"]).content
with open(f"photos/{counter}_{date}.jpg", "wb") as image_handler:
image_handler.write(image_data)
elif media["Type"] == "video/mp4":
urllib.request.urlretrieve(media["Url"], f"videos/{counter}_{date}.mp4")
else:
print(media["Type"])

counter += 1
print(f"{page=}, {counter=}, {date=}")

page += 1
Empty file removed scripts/.gitkeep
Empty file.

0 comments on commit c1c97ae

Please sign in to comment.