| 1 | + | #!/usr/bin/env python3 |
| 2 | + | import random |
| 3 | + | from argparse import ArgumentParser, RawDescriptionHelpFormatter |
| 4 | + | |
| 5 | + | from maigret.maigret import MaigretDatabase |
| 6 | + | from maigret.submit import get_alexa_rank |
| 7 | + | |
| 8 | + | |
| 9 | + | def update_tags(site): |
| 10 | + | tags = [] |
| 11 | + | if not site.tags: |
| 12 | + | print(f'Site {site.name} doesn\'t have tags') |
| 13 | + | else: |
| 14 | + | tags = site.tags |
| 15 | + | print(f'Site {site.name} tags: ' + ', '.join(tags)) |
| 16 | + | |
| 17 | + | print(f'URL: {site.url_main}') |
| 18 | + | |
| 19 | + | new_tags = set(input('Enter new tags: ').split(', ')) |
| 20 | + | if "disabled" in new_tags: |
| 21 | + | new_tags.remove("disabled") |
| 22 | + | site.disabled = True |
| 23 | + | |
| 24 | + | print(f'Old alexa rank: {site.alexa_rank}') |
| 25 | + | rank = get_alexa_rank(site.url_main) |
| 26 | + | if rank: |
| 27 | + | print(f'New alexa rank: {rank}') |
| 28 | + | site.alexa_rank = rank |
| 29 | + | |
| 30 | + | site.tags = [x for x in list(new_tags) if x] |
| 31 | + | |
| 32 | + | |
| 33 | + | if __name__ == '__main__': |
| 34 | + | parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter |
| 35 | + | ) |
| 36 | + | parser.add_argument("--base","-b", metavar="BASE_FILE", |
| 37 | + | dest="base_file", default="maigret/resources/data.json", |
| 38 | + | help="JSON file with sites data to update.") |
| 39 | + | |
| 40 | + | pool = list() |
| 41 | + | |
| 42 | + | args = parser.parse_args() |
| 43 | + | |
| 44 | + | db = MaigretDatabase() |
| 45 | + | db.load_from_file(args.base_file).sites |
| 46 | + | |
| 47 | + | while True: |
| 48 | + | site = random.choice(db.sites) |
| 49 | + | if site.engine == 'uCoz' or site.tags: |
| 50 | + | continue |
| 51 | + | |
| 52 | + | update_tags(site) |
| 53 | + | |
| 54 | + | db.save_to_file(args.base_file) |