Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion legi/anomalies.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ def err(path, *a):
return count[0]


if __name__ == '__main__':
def main():
p = ArgumentParser()
p.add_argument('db')
args = p.parse_args()
detect_anomalies(connect_db(args.db))


if __name__ == '__main__':
main()
6 changes: 5 additions & 1 deletion legi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ def download_legi_via_http(dst_dir):
os.rename(filepath + '.part', filepath)


if __name__ == '__main__':
def main():
p = argparse.ArgumentParser()
p.add_argument('directory')
p.add_argument('-r', '--retry', action='store_true', default=False,
help="if the download fails, retry every hour for up to 6 hours")
args = p.parse_args()
retry_hours = 6 if args.retry else 0
download_legi(args.directory, retry_hours=retry_hours)


if __name__ == '__main__':
main()
10 changes: 7 additions & 3 deletions legi/factorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def factorize_by(db, key):
print('factorized %i duplicates into %i uniques based on %s' % (total, factorized, key))


def main(db):
def run(db):
print("> Factorisation des textes...")

connect_by_nature_num(db)
Expand Down Expand Up @@ -233,7 +233,7 @@ def main(db):
print("Il y a désormais %i textes dans la base." % n)


if __name__ == '__main__':
def main():
p = ArgumentParser()
p.add_argument('db')
p.add_argument('--from-scratch')
Expand All @@ -249,6 +249,10 @@ def main(db):
""")
if db.one("SELECT id FROM textes_versions WHERE titrefull_s IS NULL LIMIT 1"):
normalize_text_titles(db)
main(db)
run(db)
except KeyboardInterrupt:
pass


if __name__ == '__main__':
main()
6 changes: 5 additions & 1 deletion legi/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def analyze(db):
print(json.dumps(stats, indent=4, sort_keys=True))


if __name__ == '__main__':
def main():
p = ArgumentParser()
p.add_argument('command', choices=['analyze', 'clean'])
p.add_argument('db')
Expand Down Expand Up @@ -738,3 +738,7 @@ def analyze(db):
finally:
if log_file:
log_file.close()


if __name__ == '__main__':
main()
6 changes: 5 additions & 1 deletion legi/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ def get_key(key, ignore_not_found=False):
log_file.write('%r => %r (%i×)\n' % (change[0], change[1], count))


if __name__ == '__main__':
def main():
p = ArgumentParser()
p.add_argument('db')
p.add_argument('what', nargs='?', default='all', choices=[
Expand All @@ -885,3 +885,7 @@ def get_key(key, ignore_not_found=False):
raise KeyboardInterrupt
except KeyboardInterrupt:
pass


if __name__ == '__main__':
main()
5 changes: 1 addition & 4 deletions legi/tar2sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,4 @@ def main():


if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
main()
Loading