green-spider/screenshots.py

29 lines
806 B
Python
Raw Normal View History

2018-08-15 22:02:20 +02:00
from google.cloud import datastore
2018-04-17 20:45:51 +02:00
import json
import sys
2018-08-15 22:02:20 +02:00
import os
2018-04-17 20:45:51 +02:00
def main():
2018-08-15 22:02:20 +02:00
if len(sys.argv) == 1:
print("Error: please provide path to Google Storage API system account JSON file as argument")
sys.exit(1)
2018-04-17 20:45:51 +02:00
2018-08-15 22:02:20 +02:00
key_path = sys.argv[1]
client = datastore.Client.from_service_account_json(key_path)
2018-04-17 20:45:51 +02:00
2018-08-15 22:02:20 +02:00
out = {}
2018-04-17 20:45:51 +02:00
2018-08-15 22:02:20 +02:00
query = client.query(kind='webscreenshot')
for item in query.fetch():
print(item['url'], os.path.basename(item['screenshot_url']))
out[item['url']] = os.path.basename(item['screenshot_url'])
2018-04-17 20:45:51 +02:00
output_filename = "./webapp/dist/data/screenshots.json"
with open(output_filename, 'w', encoding="utf8") as jsonfile:
2018-08-15 22:02:20 +02:00
json.dump(out, jsonfile, indent=2, sort_keys=True, ensure_ascii=False)
2018-04-17 20:45:51 +02:00
if __name__ == "__main__":
main()