Created
June 12, 2019 16:15
-
-
Save categulario/43910dce34f4cdfab439b6d01f1bd94f to your computer and use it in GitHub Desktop.
Toma mi archivo de strava y organízalo por mes para subir a nextcloud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess | |
import csv | |
import os | |
from datetime import datetime | |
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
OUT_DIR = os.path.join(BASE_DIR, 'output') | |
def main(): | |
with open('./activities.csv') as activitiesfile: | |
reader = csv.DictReader(activitiesfile) | |
for line in reader: | |
date = datetime.strptime(line['date'], '%Y-%m-%d %H:%M:%S') | |
directory = date.strftime('%Y-%m') | |
abs_dir = os.path.join(OUT_DIR, directory) | |
if not os.path.isdir(abs_dir): | |
os.makedirs(abs_dir) | |
new_name = date.strftime('%Y-%m-%d_%H_%M_%a.gpx') | |
new_loc = os.path.join(abs_dir, new_name) | |
subprocess.run('cp {} {}'.format(line['filename'], new_loc).split()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment