Works with multiple sheets (hardcoded)

pull/9/head
Logan Williams 2021-01-19 10:04:30 +00:00
rodzic f6abb0fb3e
commit e55a4d55dc
1 zmienionych plików z 74 dodań i 68 usunięć

Wyświetl plik

@ -11,8 +11,10 @@ from botocore.errorfactory import ClientError
load_dotenv()
gc = gspread.service_account()
sh = gc.open("Bellingcat media archiver")
wks = sh.sheet1
sh = gc.open("Media Sheet (January 16-20 + People)")
for ii in range(5):
wks = sh.get_worksheet(ii)
values = wks.get_all_values()
ydl_opts = {'outtmpl': 'tmp/%(id)s.%(ext)s', 'quiet': False}
@ -27,11 +29,11 @@ s3_client = boto3.client('s3',
for i in range(2, len(values)+1):
v = values[i-1]
if v[2] == "":
print(v[0])
if v[1] != "" and v[10] == "":
print(v[1])
try:
info = ydl.extract_info(v[0], download=False)
info = ydl.extract_info(v[1], download=False)
if 'entries' in info:
if len(info['entries']) > 1:
@ -51,10 +53,10 @@ for i in range(2, len(values)+1):
# file exists
update = [{
'range': 'C' + str(i),
'range': 'K' + str(i),
'values': [['already archived']]
}, {
'range': 'D' + str(i),
'range': 'M' + str(i),
'values': [[cdn_url]]
}]
@ -64,29 +66,33 @@ for i in range(2, len(values)+1):
# Not found
# sometimes this results in a different filename, so do this again
info = ydl.extract_info(v[0], download=True)
info = ydl.extract_info(v[1], download=True)
if 'entries' in info:
filename = ydl.prepare_filename(info['entries'][0])
else:
filename = ydl.prepare_filename(info)
if not os.path.exists(filename):
filename = filename.split('.')[0] + '.mkv'
print(filename)
key = filename.split('/')[1]
cdn_url = 'https://{}.{}.cdn.digitaloceanspaces.com/{}'.format(os.getenv('DO_BUCKET'), os.getenv('DO_SPACES_REGION'), key)
# with open(filename, 'rb') as f:
# s3_client.upload_fileobj(f, Bucket=os.getenv('DO_BUCKET'), Key=key, ExtraArgs={'ACL': 'public-read'})
with open(filename, 'rb') as f:
s3_client.upload_fileobj(f, Bucket=os.getenv('DO_BUCKET'), Key=key, ExtraArgs={'ACL': 'public-read'})
os.remove(filename)
update = [{
'range': 'C' + str(i),
'values': [['successful-desktop']]
'range': 'K' + str(i),
'values': [['successful']]
}, {
'range': 'B' + str(i),
'range': 'L' + str(i),
'values': [[datetime.datetime.now().isoformat()]]
}, {
'range': 'D' + str(i),
'range': 'M' + str(i),
'values': [[cdn_url]]
}]
@ -95,10 +101,10 @@ for i in range(2, len(values)+1):
t, value, traceback = sys.exc_info()
update = [{
'range': 'C' + str(i),
'range': 'K' + str(i),
'values': [[str(value)]]
}, {
'range': 'B' + str(i),
'range': 'L' + str(i),
'values': [[datetime.datetime.now().isoformat()]]
}]