|
@@ -1,55 +0,0 @@
|
|
|
-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)
|
|
|
|
|
-
|
|
|
|
|
-if __name__ == '__main__':
|
|
|
|
|
- main()
|
|
|
|
|
- sys.exit(0)
|
|
|