1
0
personal-data/personal_data/__main__.py

62 lines
1.7 KiB
Python
Raw Normal View History

2024-04-16 21:23:27 +00:00
import argparse
2024-04-16 22:45:15 +00:00
import logging
2024-04-16 21:23:27 +00:00
2024-04-23 20:58:25 +00:00
import personal_data.main
2024-06-02 21:14:19 +00:00
from personal_data.notification import NotificationType
2024-04-23 20:58:25 +00:00
2024-04-16 21:23:27 +00:00
def parse_arguments():
2024-04-28 21:45:47 +00:00
available_scraper_names = personal_data.main.available_scraper_names()
2024-08-25 18:56:47 +00:00
if len(available_scraper_names) == 0:
msg = 'Failed to load any scrapers'
raise Exception(msg)
2024-07-22 14:58:42 +00:00
parser = argparse.ArgumentParser(
epilog='Available fetchers: ' + ' '.join(available_scraper_names),
)
2024-05-09 14:59:56 +00:00
parser.add_argument(
'fetchers',
metavar='FETCHER',
type=str,
nargs='+',
choices=available_scraper_names,
)
2024-04-23 20:58:25 +00:00
parser.add_argument('--cookiejar', action='store_true')
2024-05-09 14:59:56 +00:00
parser.add_argument('--email', action='store_true', dest='send_email_notification')
2024-06-02 21:16:11 +00:00
parser.add_argument(
2024-06-06 21:50:29 +00:00
'--loud-sound',
action='store_true',
dest='trigger_loud_and_annoying_sound',
2024-06-02 21:16:11 +00:00
)
2024-06-02 22:00:01 +00:00
parser.add_argument(
2024-06-06 21:50:29 +00:00
'--ignore-cache',
action='store_true',
dest='ignore_cache',
2024-06-02 22:00:01 +00:00
)
2024-04-16 21:23:27 +00:00
return parser.parse_args()
2024-04-23 20:58:25 +00:00
2024-04-16 21:23:27 +00:00
def main():
2024-04-16 22:45:15 +00:00
logging.basicConfig()
logging.getLogger('personal_data').setLevel('INFO')
2024-04-16 21:23:27 +00:00
args = parse_arguments()
scraper_filter = frozenset(args.fetchers)
2024-06-02 21:14:19 +00:00
# Determine notification sounds
notification_types = set()
if args.send_email_notification:
notification_types.add(NotificationType.EMAIL)
if args.trigger_loud_and_annoying_sound:
notification_types.add(NotificationType.LOUD_SOUND)
2024-05-09 14:59:56 +00:00
personal_data.main.main(
scraper_filter,
use_cookiejar=args.cookiejar,
2024-06-02 21:16:11 +00:00
notification_types=frozenset(notification_types),
2024-06-06 21:50:29 +00:00
ignore_cache=args.ignore_cache,
2024-05-09 14:59:56 +00:00
)
2024-04-23 20:58:25 +00:00
2024-03-31 22:55:55 +00:00
2023-12-10 23:27:56 +00:00
if __name__ == '__main__':
2024-04-16 21:23:27 +00:00
main()