]> code.communitydata.science - cdsc_reddit.git/commitdiff
Check the shas when we download dumps
authorNate E TeBlunthuis <nathante@n2347.hyak.local>
Tue, 7 Jul 2020 06:31:52 +0000 (23:31 -0700)
committerNate E TeBlunthuis <nathante@n2347.hyak.local>
Tue, 7 Jul 2020 06:31:52 +0000 (23:31 -0700)
check_comments_shas.py [new file with mode: 0644]
pull_pushshift_comments.sh
pull_pushshift_submissions.sh

diff --git a/check_comments_shas.py b/check_comments_shas.py
new file mode 100644 (file)
index 0000000..a2bc89b
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+# run from a build_machine
+
+import requests
+from os import path
+import hashlib
+
+shasums = requests.get("https://files.pushshift.io/reddit/comments/sha256sums.txt").text
+
+dumpdir = "/gscratch/comdata/raw_data/reddit_dumps/comments"
+
+for l in shasums.strip().split('\n'):
+    sha256_hash = hashlib.sha256()
+    parts = l.split(' ')
+
+    correct_sha256 = parts[0]
+    filename = parts[-1]
+    print(f"checking {filename}")
+    fpath = path.join(dumpdir,filename)
+    if path.isfile(fpath):
+        with open(fpath,'rb') as f:
+            for byte_block in iter(lambda: f.read(4096),b""):
+                sha256_hash.update(byte_block)
+
+        if sha256_hash.hexdigest() == correct_sha256:
+            print(f"{filename} checks out")
+        else:
+            print(f"ERROR! {filename} has the wrong hash. Redownload and recheck!")
+    else:
+        print(f"Skipping {filename} as it doesn't exist")
+
index bfe3938bddecee11c391ebac88e746895bea8851..243e46480dc6c55374a479e0835663a7317513e1 100755 (executable)
@@ -8,5 +8,4 @@ wget -r --no-parent -A 'RC_20*.bz2' -U $user_agent -P $output_dir -nd -nc $base_
 wget -r --no-parent -A 'RC_20*.xz' -U $user_agent -P $output_dir -nd -nc $base_url
 wget -r --no-parent -A 'RC_20*.zst' -U $user_agent -P $output_dir -nd -nc $base_url
 
-
-
+./check_comment_shas.py
index f64a09f7b8a7b7a11fa968d2cb7d3d4704c68a24..5a53c87d4bb24ef6818295ef3760d76bf58fc13e 100755 (executable)
@@ -11,4 +11,4 @@ wget -r --no-parent -A 'RS_20*.bz2' -U $user_agent -P $output_dir -nd -nc $base_
 wget -r --no-parent -A 'RS_20*.xz' -U $user_agent -P $output_dir -nd -nc $base_url/old_v1_data/
 wget -r --no-parent -A 'RS_20*.zst' -U $user_agent -P $output_dir -nd -nc $base_url/old_v1_data/
 
-
+./check_submissions_shas.py

Community Data Science Collective || Want to submit a patch?