Пример #1
0
def run_cli():
    import argparse
    import sys

    parser = argparse.ArgumentParser(description='Fetch photos from IMAP.')
    parser.add_argument('--verbose', '-v', dest='verbose',
                        default=0, action='count',
                        help='Prints actions on stdout.')
    parser.add_argument('--host', dest='host',
                        required=True,
                        help='IMAP Hostname')
    parser.add_argument('--login', '-l', dest='login',
                        required=True,
                        help='IMAP Username')
    parser.add_argument('--password', '-p', dest='password',
                        help='IMAP password.')
    parser.add_argument('--destination', '-d', dest='destination',
                        required=True,
                        help='The folder where files will be stored')
    parser.add_argument('--force', dest='force',
                        action='store_true', default=False,
                        help='Force fecthing mails. Even if they are read or '
                        'in the index')

    args = parser.parse_args()

    if args.verbose >= 2:
        Simple.basicConfig(level=logging.DEBUG, stream=sys.stdout)
    elif args.verbose >= 1:
        Simple.basicConfig(level=logging.INFO, stream=sys.stdout)
    else:
        Simple.basicConfig(level=logging.WARNING)

    if not args.password:
        from getpass import getpass
        password = getpass('Password: '******'Unable to connect: {}'.format(exc), file=sys.stderr)
        sys.exit(1)

    try:
        fetcher.fetch()
    except Exception as exc:
        LOG.critical('Unable to fetch: {}'.format(exc), file=sys.stderr)
        sys.exit(1)

    sys.exit(0)
Пример #2
0
def setup_logging(args):
    Simple.basicConfig(level=logging.DEBUG)
Пример #3
0
        args.login,
        password,
        True,
        args.destination,
        args.force)
    try:
        fetcher.connect()
    except Exception as exc:
        LOG.critical('Unable to connect: {}'.format(exc), file=sys.stderr)
        sys.exit(1)

    try:
        fetcher.fetch()
    except Exception as exc:
        LOG.critical('Unable to fetch: {}'.format(exc), file=sys.stderr)
        sys.exit(1)

    sys.exit(0)

if __name__ == '__main__':
    from getpass import getpass
    Simple.basicConfig(level=logging.DEBUG)
    fetcher = MailFetcher(
        input('Host: '),
        input('Login: '******'Password: '******'/tmp/lost_images')
    fetcher.connect()
    fetcher.fetch()
Пример #4
0
import logging
from datetime import datetime
from io import StringIO
from os import getenv
from pathlib import Path
from typing import Any, Dict, Generator, Optional

import pytz
import requests
from dateutil.parser import parse
from gouge.colourcli import Simple
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

LOG = logging.getLogger(__name__)
Simple.basicConfig(level=logging.INFO)
UTC = pytz.timezone("UTC")
Lux = pytz.timezone("Europe/Luxembourg")


def maybe_float(value: Optional[str]) -> Optional[float]:
    if value is None or value == "":
        return None
    return float(value)


class Client:
    def __init__(self, url: str, auth_file_name: str) -> None:
        self.url = url
        if url == "":
            raise ValueError("URL cannot be empty!")