kopia lustrzana https://github.com/bellingcat/auto-archiver
Detect columns from header names, fixes #2
rodzic
a0180ccaaa
commit
f40b924d0d
|
@ -32,8 +32,12 @@ def index_to_col(index):
|
||||||
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
|
||||||
if index > 25:
|
if index > 25:
|
||||||
t = math.floor(index / 26)
|
t = index
|
||||||
return alphabet[t - 1] + index_to_col(index - t * 26)
|
dig = 0
|
||||||
|
while t > 25:
|
||||||
|
t = math.floor(t / 26)
|
||||||
|
dig += 1
|
||||||
|
return alphabet[t - 1] + index_to_col(index - t * int(math.pow(26, dig)))
|
||||||
else:
|
else:
|
||||||
return alphabet[index]
|
return alphabet[index]
|
||||||
|
|
||||||
|
@ -100,19 +104,19 @@ def update_sheet(wks, row, status, url, columns):
|
||||||
|
|
||||||
if url is not None and columns['archive'] is not None:
|
if url is not None and columns['archive'] is not None:
|
||||||
update += [{
|
update += [{
|
||||||
'range': args.archive + str(row),
|
'range': columns['archive'] + str(row),
|
||||||
'values': [[url]]
|
'values': [[url]]
|
||||||
}]
|
}]
|
||||||
|
|
||||||
if columns['status'] is not None:
|
if columns['status'] is not None:
|
||||||
update += [{
|
update += [{
|
||||||
'range': args.status + str(row),
|
'range': columns['status'] + str(row),
|
||||||
'values': [[status]]
|
'values': [[status]]
|
||||||
}]
|
}]
|
||||||
|
|
||||||
if columns['date'] is not None:
|
if columns['date'] is not None:
|
||||||
update += [{
|
update += [{
|
||||||
'range': args.date + str(row),
|
'range': columns['date'] + str(row),
|
||||||
'values': [[datetime.datetime.now().isoformat()]]
|
'values': [[datetime.datetime.now().isoformat()]]
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
@ -126,10 +130,6 @@ def main():
|
||||||
parser.add_argument('--streaming', dest='streaming', action='store_true')
|
parser.add_argument('--streaming', dest='streaming', action='store_true')
|
||||||
parser.add_argument('--all-worksheets',
|
parser.add_argument('--all-worksheets',
|
||||||
dest='all_worksheets', action='store_true')
|
dest='all_worksheets', action='store_true')
|
||||||
# parser.add_argument('--url-col', dest='url', action='store')
|
|
||||||
# parser.add_argument('--archive-col', dest='archive', action='store')
|
|
||||||
# parser.add_argument('--date-col', dest='date', action='store')
|
|
||||||
# parser.add_argument('--status-col', dest='status', action='store')
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print("Opening document " + args.sheet)
|
print("Opening document " + args.sheet)
|
||||||
|
@ -156,6 +156,8 @@ def main():
|
||||||
|
|
||||||
columns['url'] = index_to_col(headers.index(
|
columns['url'] = index_to_col(headers.index(
|
||||||
'Media URL')) if 'Media URL' in headers else None
|
'Media URL')) if 'Media URL' in headers else None
|
||||||
|
url_index = col_to_index(columns['url'])
|
||||||
|
|
||||||
columns['archive'] = index_to_col(headers.index(
|
columns['archive'] = index_to_col(headers.index(
|
||||||
'Archive location')) if 'Archive location' in headers else None
|
'Archive location')) if 'Archive location' in headers else None
|
||||||
columns['date'] = index_to_col(headers.index(
|
columns['date'] = index_to_col(headers.index(
|
||||||
|
@ -163,15 +165,15 @@ def main():
|
||||||
columns['status'] = index_to_col(headers.index(
|
columns['status'] = index_to_col(headers.index(
|
||||||
'Archive status')) if 'Archive status' in headers else None
|
'Archive status')) if 'Archive status' in headers else None
|
||||||
|
|
||||||
|
if columns['url'] is None:
|
||||||
|
print("No 'Media URL' column found, skipping")
|
||||||
|
continue
|
||||||
|
|
||||||
# loop through rows in worksheet
|
# loop through rows in worksheet
|
||||||
for i in range(2, len(values)+1):
|
for i in range(2, len(values)+1):
|
||||||
v = values[i-1]
|
v = values[i-1]
|
||||||
|
|
||||||
url_index = col_to_index(args.url)
|
if v[url_index] != "" and v[col_to_index(columns['status'])] == "":
|
||||||
|
|
||||||
if v[url_index] != "" and v[col_to_index(args.status)] == "":
|
|
||||||
print(v[col_to_index(args.url)])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'outtmpl': 'tmp/%(id)s.%(ext)s', 'quiet': False}
|
'outtmpl': 'tmp/%(id)s.%(ext)s', 'quiet': False}
|
||||||
|
@ -179,7 +181,7 @@ def main():
|
||||||
info = ydl.extract_info(v[url_index], download=False)
|
info = ydl.extract_info(v[url_index], download=False)
|
||||||
|
|
||||||
if args.streaming and 'is_live' in info and info['is_live']:
|
if args.streaming and 'is_live' in info and info['is_live']:
|
||||||
wks.update(args.status + str(i), 'Recording stream')
|
wks.update(columns['status'] + str(i), 'Recording stream')
|
||||||
cdn_url, status = download_vid(v[url_index], s3_client)
|
cdn_url, status = download_vid(v[url_index], s3_client)
|
||||||
update_sheet(wks, i, status, cdn_url, columns)
|
update_sheet(wks, i, status, cdn_url, columns)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
Ładowanie…
Reference in New Issue