-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdl_attachment.py
34 lines (31 loc) · 1.11 KB
/
dl_attachment.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
import requests
import os
import sys
# grab this from an old-jira session after you've logged in
auth_cookie = ''#TODO: INSERT YOUR ACTUAL COOKIE'
if not auth_cookie:
sys.exit("You must provide a valid JIRA auth cookie")
s = requests.Session()
s.headers.update({'Cookie': auth_cookie})
with open('attachments.txt') as f:
for url in f:
image = url.rstrip()
filepath = image.removeprefix('https://jira.wnyc.org/secure/attachment/') # python3.9 only
try:
folder, filename = filepath.split('/')
except ValueError:
vals = filepath.split('/')
filename = vals[-1]
folder = "/".join(vals[:-1])
try:
os.makedirs(os.path.join('attachments', folder), exist_ok=True)
except:
pass
try:
with open(os.path.join('attachments', folder, filename), 'wb') as img:
r = s.get(image)
img.write(r.content)
print(f'saved {os.path.join("attachments", folder, filename)}')
except OSError:
print('could not upload', filename)
pass