<commit_before>#!/usr/bin/python3.5
"""Deletes webapp logs.

- gets list of logs via api
- deletes logs via api

Usage:
  pa_delete_webapp_logs.py [--domain=<domain>] [--log_type=<log_type>]

Options:
  --domain=<domain>         Domain name, eg www.mydomain.com   [default: your-username.pythonanywhere.com]
  --log_type                Log type, could be access, error, server or all   [default: all]
  --log_index               Log index, 0 for current log, 1-9 for one of archive logs or all [default: all]
"""

from docopt import docopt
import getpass
import os

from pythonanywhere.api import Webapp
from pythonanywhere.snakesay import snakesay


def main(domain, log_type, log_index):
    if domain == 'your-username.pythonanywhere.com':
        username = getpass.getuser().lower()
        pa_domain = os.environ.get('PYTHONANYWHERE_DOMAIN', 'pythonanywhere.com')
        domain = '{username}.{pa_domain}'.format(username=username, pa_domain=pa_domain)

    webapp = Webapp(domain)
    log_types = ["access", "error", "server"]
    logs = webapp.get_log_info()
    if log_type == "all" and log_index == "all":
        for key in log_types:
            for log in logs[key]:
                webapp.delete_log(key, log)<commit_msg>corrected help text to be parsed by docopt<commit_after>#!/usr/bin/python3.5
"""Deletes webapp logs.

- gets list of logs via api
- deletes logs via api

Usage:
  pa_delete_webapp_logs.py [--domain=<domain>] [--log_type=<log_type>]

Options:
  --domain=<domain>         Domain name, eg www.mydomain.com   [default: your-username.pythonanywhere.com]
  --log_type=<log_type>     Log type, could be access, error, server or all   [default: all]
  --log_index=<log_index>   Log index, 0 for current log, 1-9 for one of archive logs or all [default: all]
"""

from docopt import docopt
import getpass
import os

from pythonanywhere.api import Webapp
from pythonanywhere.snakesay import snakesay


def main(domain, log_type, log_index):
    if domain == 'your-username.pythonanywhere.com':
        username = getpass.getuser().lower()
        pa_domain = os.environ.get('PYTHONANYWHERE_DOMAIN', 'pythonanywhere.com')
        domain = '{username}.{pa_domain}'.format(username=username, pa_domain=pa_domain)

    webapp = Webapp(domain)
    log_types = ["access", "error", "server"]
    logs = webapp.get_log_info()
    if log_type == "all" and log_index == "all":
        for key in log_types:
            for log in logs[key]:
                webapp.delete_log(key, log)
{'fraction_non_alphanumeric': 0.12004801920768307, 'fraction_numerical': 0.004001600640256103, 'mean_word_length': 3.332755632582322, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6518182', 'n_tokens_mistral': 834, 'n_tokens_neox': 807, 'n_words': 226}