<commit_before>#! /usr/bin/env python
# -*- coding: utf-8 -*-

"""JupyterHub backup for the PAAD project
Author: <NAME> <<EMAIL>>

"""

import time
from datetime import datetime, timedelta
from subprocess import check_output, CalledProcessError
from threading import Timer

from fabric.api import local

username = "" # Enter Docker Hub USERNAME <paad>
password = "" # Enter Docker Hub user PASSWORD
email = "" # Enter Docker Hub user EMAIL <<EMAIL>>
docker_hub_repo_name = "" # Enter Docker Hub repository name <jupyterhub>
docker_container_name = "" # Enter Docker container name <all_jupyterhub_1>

def backup():
    """Backup from running container to Docker Hub repository"""

    def login():
        """Automatic Docker login"""
        
        try:
            local("docker login --username=%s --password=%s --email=%s" %
                    (username, password, email))
        except Exception:
            pass

    docker_hub_repo = username + '/' + docker_hub_repo_name            
    # Check Docker image id
    try:
        image_id = check_output("docker images -q %s" % docker_hub_repo,
                                shell=True)
        image_id = image_id.strip()
    except CalledProcessError:
        image_id = None
    # Docker commit
    try:
        local("docker commit %s %s" % (docker_container_name, docker_hub_repo))
    except Exception:
        pass
    # Delete previous Docker image
    if image_id != None:
        try:
            local("docker rmi %s" % image_id)
        except Exception:
            pass
    # Docker push
    try:
        local("docker push %s" % docker_hub_repo)
    except Exception:
        login()

while True:
    date_time_current = datetime.now()
    date_time_action = date_time_current + timedelta(hours=12, minutes=0,
                                                     seconds=0, microseconds=0)
    delta_date_time = date_time_action - date_time_current
    seconds_delta_date_time = delta_date_time.seconds
    t = Timer(seconds_delta_date_time, backup)
    t.start()
    time.sleep(seconds_delta_date_time)<commit_msg>[backupscript] Fix login to Docker<commit_after>#! /usr/bin/env python
# -*- coding: utf-8 -*-

"""JupyterHub backup for the PAAD project
Author: <NAME> <<EMAIL>>

"""

import time
from datetime import datetime, timedelta
from subprocess import check_output, CalledProcessError
from threading import Timer

from fabric.api import local

docker_hub_username = "" # Enter Docker Hub USERNAME <paad>
docker_hub_password = "" # Enter Docker Hub user PASSWORD
docker_hub_email = "" # Enter Docker Hub user EMAIL <<EMAIL>>
docker_hub_repo_name = "" # Enter Docker Hub repository name <jupyterhub>
docker_container_name = "" # Enter Docker container name <all_jupyterhub_1>

def backup():
    """Backup from running container to Docker Hub repository"""

    docker_hub_repo = docker_hub_username + '/' + docker_hub_repo_name
    # Check Docker image id
    try:
        image_id = check_output("docker images -q %s" % docker_hub_repo,
                                shell=True)
        image_id = image_id.strip()
    except CalledProcessError:
        image_id = None
    # Docker commit
    try:
        local("docker commit %s %s" % (docker_container_name, docker_hub_repo))
    except Exception:
        pass
    # Delete previous Docker image
    if image_id != None:
        try:
            local("docker rmi %s" % image_id)
        except Exception:
            pass
    # Docker push
    try:
        local("docker push %s" % docker_hub_repo)
    except Exception:
        pass

def login():
    """Automatic Docker login"""

    try:
        local("docker login --username=%s --password=%s --email=%s" %
                (docker_hub_username, docker_hub_password, docker_hub_email))
    except Exception:
        pass

login()       
while True:
    date_time_current = datetime.now()
    date_time_action = date_time_current + timedelta(hours=12, minutes=0,
                                                     seconds=0, microseconds=0)
    delta_date_time = date_time_action - date_time_current
    seconds_delta_date_time = delta_date_time.seconds
    t = Timer(seconds_delta_date_time, backup)
    t.start()
    time.sleep(seconds_delta_date_time)
{'fraction_non_alphanumeric': 0.09176470588235294, 'fraction_numerical': 0.0032941176470588237, 'mean_word_length': 2.655202063628547, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1038047', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1209, 'n_words': 346}