@@ -51,7 +51,7 @@ def upload_dataset(url, bucket_name, stable_id):
51
51
timestamp_blob = bucket .blob (f"{ stable_id } /{ timestamp } .zip" )
52
52
timestamp_blob .upload_from_string (content )
53
53
return file_md5_hash , timestamp_blob .public_url
54
- return None , None
54
+ return file_md5_hash , None
55
55
56
56
57
57
def create_bucket (bucket_name ):
@@ -105,26 +105,25 @@ def batch_dataset(request):
105
105
feed_id = result [2 ]
106
106
try :
107
107
md5_file_hash , hosted_url = upload_dataset (producer_url , bucket_name , stable_id )
108
- if md5_file_hash is not None :
109
- continue
108
+
110
109
# Set up transaction for SQL updates
111
110
connection = engine .connect ()
112
111
transaction = connection .begin ()
113
112
114
113
# Create a new version of the dataset in the database
115
114
select_dataset_statement = text (f"select id, hash from gtfsdataset where latest=true and feed_id='{ feed_id } '" )
116
115
dataset_results = connection .execute (select_dataset_statement ).all ()
117
- dataset_id = dataset_results [0 ][0 ]
118
- dataset_hash = dataset_results [0 ][1 ]
116
+ dataset_id = dataset_results [0 ][0 ] if len ( dataset_results ) > 0 else None
117
+ dataset_hash = dataset_results [0 ][1 ] if len ( dataset_results ) > 0 else None
119
118
120
119
# Set the previous version latest field to false
121
120
if dataset_hash is not None :
122
121
sql_statement = f"update gtfsdataset set latest=false where id='{ dataset_id } '"
123
122
connection .execute (text (sql_statement ))
124
123
125
- sql_statement = f"insert into gtfsdataset (id, feed_id, latest, bounding_box, hosted_url, note, hash, " \
124
+ sql_statement = f"insert into gtfsdataset (id, feed_id, latest, bounding_box, note, hash, " \
126
125
f"download_date, stable_id, hosted_url) " \
127
- f"select '{ str (uuid .uuid4 ())} ', feed_id, true, bounding_box, hosted_url, note, " \
126
+ f"select '{ str (uuid .uuid4 ())} ', feed_id, true, bounding_box, note, " \
128
127
f"'{ md5_file_hash } ', NOW(), stable_id, '{ hosted_url } ' from " \
129
128
f"gtfsdataset where id='{ dataset_id } '"
130
129
0 commit comments