|
@@ -1,30 +1,55 @@
|
|
|
-import pandas as pd
|
|
|
|
|
-import sys
|
|
|
|
|
import json
|
|
import json
|
|
|
|
|
+import sys
|
|
|
|
|
+import csv
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def nacti(path):
|
|
|
|
|
+ data = []
|
|
|
|
|
+ with open(path, 'r', encoding='utf8') as fp:
|
|
|
|
|
+ reading = csv.DictReader(fp)
|
|
|
|
|
+ for row in reading:
|
|
|
|
|
+ data.append(row['JSON'])
|
|
|
|
|
+ return data
|
|
|
|
|
+
|
|
|
|
|
+def ulozit(saving_csv, name_csv):
|
|
|
|
|
+ with open(name_csv + ".csv", "w", encoding="utf8", newline='') as f:
|
|
|
|
|
+ writer = csv.DictWriter(f, fieldnames=['JSON'])
|
|
|
|
|
+ writer.writeheader()
|
|
|
|
|
+ for radek in saving_csv:
|
|
|
|
|
+ writer.writerow({'JSON': radek})
|
|
|
|
|
+
|
|
|
|
|
+def odstranit(csv_json, clear_json):
|
|
|
|
|
+ for s in csv_json:
|
|
|
|
|
+ if isinstance(s, str) and ',' in s:
|
|
|
|
|
+ idx = s.rfind(',')
|
|
|
|
|
+ clear_json.add(s[:idx])
|
|
|
|
|
+ else:
|
|
|
|
|
+ clear_json.add(s)
|
|
|
|
|
+
|
|
|
|
|
+def nactenicsv(pattern_csv, target_csv):
|
|
|
|
|
+ missing = set()
|
|
|
|
|
+ overstay = set()
|
|
|
|
|
+ pattern_jsons = set(json.dumps(json.loads(x), sort_keys=True) for x in pattern_csv)
|
|
|
|
|
+ target_jsons = set(json.dumps(json.loads(x), sort_keys=True) for x in target_csv)
|
|
|
|
|
+ missing_jsons = pattern_jsons - target_jsons
|
|
|
|
|
+ overstay_jsons = target_jsons - pattern_jsons
|
|
|
|
|
+ odstranit(missing_jsons, missing)
|
|
|
|
|
+ odstranit(overstay_jsons, overstay)
|
|
|
|
|
+ ulozit(missing, "pridat")
|
|
|
|
|
+ ulozit(overstay, "odebrat")
|
|
|
|
|
+
|
|
|
|
|
+def main():
|
|
|
|
|
+ if len(sys.argv) < 3:
|
|
|
|
|
+ print('Chybi cesta k csv souborum.', file=sys.stderr)
|
|
|
|
|
+ print('Zadejte takto: <nazev_programu.py> <cesta k vzorove.csv> <cesta k cilove.csv>', file=sys.stderr)
|
|
|
|
|
+ sys.exit(1)
|
|
|
|
|
+ path_pattern = sys.argv[1]
|
|
|
|
|
+ path_target = sys.argv[2]
|
|
|
|
|
+ pattern = nacti(path_pattern)
|
|
|
|
|
+ target = nacti(path_target)
|
|
|
|
|
+
|
|
|
|
|
+ nactenicsv(pattern, target)
|
|
|
|
|
|
|
|
-vzor = None
|
|
|
|
|
-cil = None
|
|
|
|
|
-
|
|
|
|
|
-def nactenicsv():
|
|
|
|
|
- cestaksouboru_vzor = sys.argv[1]
|
|
|
|
|
- vzor = pd.read_csv(cestaksouboru_vzor)
|
|
|
|
|
- cestaksouboru_cil = sys.argv[2]
|
|
|
|
|
- cil = pd.read_csv(cestaksouboru_cil)
|
|
|
|
|
- vzor_jsons = set(json.dumps(json.loads(x), sort_keys=True) for x in vzor['JSON'])
|
|
|
|
|
- cil_jsons = set(json.dumps(json.loads(x), sort_keys=True) for x in cil['JSON'])
|
|
|
|
|
-
|
|
|
|
|
-def ulozit(ukladane_csv, nazev_csv):
|
|
|
|
|
- pd.DataFrame(list(ukladane_csv), columns=['JSON']).to_csv(nazev_csv, index=False)
|
|
|
|
|
-
|
|
|
|
|
-#main
|
|
|
|
|
-#def main() -> None:
|
|
|
|
|
-nactenicsv()
|
|
|
|
|
-vzor_jsons = set(json.dumps(json.loads(x), sort_keys=True) for x in vzor['JSON'])
|
|
|
|
|
-cil_jsons = set(json.dumps(json.loads(x), sort_keys=True) for x in cil['JSON'])
|
|
|
|
|
-chybi_jsons = vzor_jsons - cil_jsons
|
|
|
|
|
-ulozit(chybi_jsons, "pridat")
|
|
|
|
|
-prebiva_jsons = cil_jsons - vzor_jsons
|
|
|
|
|
-ulozit(prebiva_jsons, "odebrat")
|
|
|
|
|
-
|
|
|
|
|
-#if __name__ == '__main__':
|
|
|
|
|
-# sys.exit(main())
|
|
|
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
|
+ main()
|
|
|
|
|
+ sys.exit(0)
|