Skip to content

Commit be6fbc6

Browse files
committed
protocol parsing fixes
1 parent 1170b04 commit be6fbc6

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

airflow/knesset_data_pipelines/committees/parsed_document_committee_sessions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010

1111
def parse_retry_error(type_, error, document_session_id, group_type_id, application_desc, stats):
12-
document_session_id = str(document_session_id)
13-
group_type_id = str(group_type_id)
14-
application_desc = str(application_desc)
1512
if error:
13+
document_session_id = str(document_session_id)
14+
group_type_id = str(group_type_id)
15+
application_desc = str(application_desc)
1616
ext = 'txt' if type_ == 'text' else 'csv'
1717
download_filepath = os.path.join(
1818
config.KNESSET_PIPELINES_DATA_PATH,

committees/download_document_committee_session.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging, os, time
33
from datapackage_pipelines_knesset.retry_get_response_content import get_retry_response_content
44
import crcmod, base64
5+
import sys
56

67

78
def get_crc32c(filename):
@@ -30,6 +31,7 @@ def process_row(row, row_index, resource_descriptor, resource_index, parameters,
3031
row.update(download_error='reached limit, skipping download')
3132
stats["download: skipped files"] += 1
3233
else:
34+
print(f'download_document_committee_session: {row_index} {row}', file=sys.stderr)
3335
error_string, content = None, ''
3436
try:
3537
content = get_retry_response_content(row["FilePath"], None, None, None, retry_num=1, num_retries=10,
@@ -52,6 +54,7 @@ def process_row(row, row_index, resource_descriptor, resource_index, parameters,
5254
stats["download: downloaded files"] += 1
5355
row.update(download_filename=rel_filename, download_filesize=os.path.getsize(filename),
5456
download_crc32c=get_crc32c(filename))
57+
print(f'download_document_committee_session: done {row_index}', file=sys.stderr)
5558
return row
5659

5760

committees/parse_meeting_protocols.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import crcmod, base64
77
import hashlib
88
import knesset_data
9+
import sys
910

1011

1112
BASE_HASH_OBJ = hashlib.md5()
@@ -55,7 +56,7 @@ def process_row(row, row_index, resource_descriptor, resource_index, parameters,
5556
and (row["FilePath"].lower().endswith('.doc') or row["FilePath"].lower().endswith('.docx'))):
5657
document_id = "{}-{}-{}".format(row["GroupTypeID"], row["DocumentCommitteeSessionID"], row["ApplicationDesc"])
5758
original_filename, ext, output_filename, full_output_filename, download_filename, full_output_hash_filename = get_filenames(row, parameters)
58-
if os.path.exists(download_filename) and row.get('download_crc32c'):
59+
if os.path.exists(download_filename) and row.get('download_crc32c') and os.path.getsize(download_filename) > 0:
5960
m = BASE_HASH_OBJ.copy()
6061
m.update(row['download_crc32c'].encode())
6162
new_cache_hash = m.hexdigest()
@@ -74,6 +75,7 @@ def process_row(row, row_index, resource_descriptor, resource_index, parameters,
7475
row[t + "_error"] = 'reached files-limit, skipping'
7576
stats[t + ": skipped files"] += 1
7677
else:
78+
print(f'parse_meeting_protocols({t}): {row_index} old_cache_hash={old_cache_hash} new_cache_hash={new_cache_hash} {row}', file=sys.stderr)
7779
error_string = None
7880
try:
7981
with open(download_filename, "rb") as f:
@@ -106,6 +108,7 @@ def process_row(row, row_index, resource_descriptor, resource_index, parameters,
106108
stats[t + ": parsed files"] += 1
107109
with open(full_output_hash_filename, 'w') as f:
108110
f.write(new_cache_hash)
111+
print(f'parse_meeting_protocols({t}): done {row_index} {row}', file=sys.stderr)
109112
else:
110113
row[t + "_error"] = 'missing download file'
111114
stats[t + ': missing download files'] += 1

0 commit comments

Comments
 (0)