Exemplo n.º 1
0
def set_user_name(message):
    if str(message.text).startswith('/back_to_settings'):
        bot.send_message(message.chat.id,
                         'Налаштування',
                         reply_markup=settings_keyboard)
        dbworker.set_state(message.chat.id, config.States.S_MENU.value)
    elif not message.text.isdigit():
        bot.send_message(message.chat.id, "Недопустимий вік")
        dbworker.set_state(message.chat.id, config.States.S_NEW_AGE.value)
    elif int(message.text) < 5 or int(message.text) > 100:
        bot.send_message(message.chat.id, "Недопустимий вік")
        dbworker.set_state(message.chat.id, config.States.S_NEW_AGE.value)
    else:
        if user_data.get_user_data(message.chat.id,
                                   config.user_sex) == 'Чоловіча':
            user_data.set_user_data(message.chat.id, config.user_age,
                                    str(message.text))
            bot.send_message(
                message.chat.id,
                "Ти змінив вік на " +
                user_data.get_user_data(message.chat.id, config.user_age),
                reply_markup=menu_keyboard)
        else:
            user_data.set_user_data(message.chat.id, config.user_age,
                                    str(message.text))
            bot.send_message(
                message.chat.id,
                "Ти змінила вік на " +
                user_data.get_user_data(message.chat.id, config.user_age),
                reply_markup=menu_keyboard)
        dbworker.set_state(message.chat.id, config.States.S_MENU.value)
Exemplo n.º 2
0
def set_user_name(message):
    if str(message.text).startswith('/back_to_settings'):
        bot.send_message(message.chat.id,
                         'Налаштування',
                         reply_markup=settings_keyboard)
        dbworker.set_state(message.chat.id, config.States.S_MENU.value)
    elif str(message.text).startswith('/'):
        bot.send_message(message.chat.id, "Недопустиме ім'я")
    else:
        if user_data.get_user_data(message.chat.id,
                                   config.user_sex) == 'Чоловіча':
            user_data.set_user_data(message.chat.id, config.user_name,
                                    str(message.text))
            bot.send_message(
                message.chat.id,
                "Ти змінив ім'я на " +
                user_data.get_user_data(message.chat.id, config.user_name),
                reply_markup=menu_keyboard)
        else:
            user_data.set_user_data(message.chat.id, config.user_name,
                                    str(message.text))
            bot.send_message(
                message.chat.id,
                "Ти змінила ім'я на " +
                user_data.get_user_data(message.chat.id, config.user_name),
                reply_markup=menu_keyboard)
        dbworker.set_state(message.chat.id, config.States.S_MENU.value)
Exemplo n.º 3
0
def cmd_info(message):
    bot.send_message(
        message.chat.id, "Тебе звуть " +
        user_data.get_user_data(message.chat.id, config.user_name) +
        "\nТобі " + user_data.get_user_data(message.chat.id, config.user_age) +
        "\nТвоя стать " +
        str.lower(user_data.get_user_data(message.chat.id, config.user_sex)))
Exemplo n.º 4
0
def reset_users_name(message):
    if user_data.get_user_data(message.chat.id, config.user_sex) == 'Чоловіча':
        user_data.set_user_data(message.chat.id, config.user_sex, 'Жіноча')
        bot.send_message(message.chat.id,
                         "Ти змінила стать на жіночу",
                         reply_markup=menu_keyboard)
    elif user_data.get_user_data(message.chat.id, config.user_sex) == 'Жіноча':
        user_data.set_user_data(message.chat.id, config.user_sex, 'Чоловіча')
        bot.send_message(message.chat.id,
                         "Ти змінив стать на чоловічу",
                         reply_markup=menu_keyboard)
    dbworker.set_state(message.chat.id, config.States.S_MENU.value)
Exemplo n.º 5
0
def login():
    syslog.syslog(syslog.LOG_WARNING, 'Logging in to docker..')

    user_data = get_user_data()

    docker = user_data['docker']
    auth = docker.get('auth')
    email = docker.get('email')

    if auth and email:
        home = expanduser('~')
        docker_cfg_file = open(home + '/.dockercfg', 'w+')

        # TODO: Right now this truncates any other login info-- consider refactoring
        auth_hash = {
            'https://index.docker.io/v1/': {
                'auth': auth,
                'email': email
            }
        }

        print(json.dumps(auth_hash), file=docker_cfg_file)

        syslog.syslog(syslog.LOG_WARNING,
                      'Successfully logged into docker as %s' % email)
Exemplo n.º 6
0
    def finalizer_view(self):
        """Performs the actual search."""
        if "userid" not in session:
            return redirect(url_for('login'))

        userid = session.get("userid")
        user = get_user_data(userid)
        user.end_task()
        save_user_data(user)

        return redirect(url_for('index'))
Exemplo n.º 7
0
    def login(self):
        """The site's landing page."""
        if request.method == 'POST':
            userid = request.form['userid']

            if len(userid) > 3:
                session['userid'] = userid
                user = get_user_data(userid)
                save_user_data(user)
                return redirect(url_for('index'))

        return make_response(
            render_template("login.html",
                            title="VIRTUAL LEARNING ENVIRONMENT PROJECT"))
Exemplo n.º 8
0
    def navigation(self):
        """Performs the actual search."""
        if "userid" not in session:
            return redirect(url_for('login'))
        userid = session.get("userid")
        user = get_user_data(userid)
        task = user.get_task()

        context = {
            "title": "Search by menu navigation",
            "results_view": url_for("results_view"),
            "categories": {},
            "task": task,
        }

        context["categories"] = self.search_engine.category_tree()
        return make_response(render_template("navigation.html", **context))
Exemplo n.º 9
0
    def index(self):
        """The test director page."""
        if "userid" not in session:
            return redirect(url_for('login'))
        userid = session.get("userid")
        user = get_user_data(userid)
        tasks = user.get_tasks()

        context = {
            "title": "VIRTUAL LEARNING ENVIRONMENT PROJECT",
            "userid": userid,
            "tasks": tasks,
            "logout_view": url_for("logout"),
        }

        response = make_response(render_template("index.html", **context))
        return response
Exemplo n.º 10
0
def notify(msg):
  if not msg:
    raise Exception("Missing message for notify")

  user_data = get_user_data()

  # Just skip if we don't have notifications in user-data
  if not user_data.get('notifications'):
    return False

  notifications = user_data['notifications']

  if notifications.get('rest'):
    notify_rest(msg, notifications['rest'])

  if notifications.get('hipchat'):
    hipchat = notifications['hipchat']
    notify_hipchat(msg, hipchat.get('token'), hipchat.get('room'))
Exemplo n.º 11
0
def notify(msg):
    if not msg:
        raise Exception("Missing message for notify")

    user_data = get_user_data()

    # Just skip if we don't have notifications in user-data
    if not user_data.get('notifications'):
        return False

    notifications = user_data['notifications']

    if notifications.get('rest'):
        notify_rest(msg, notifications['rest'])

    if notifications.get('hipchat'):
        hipchat = notifications['hipchat']
        notify_hipchat(msg, hipchat.get('token'), hipchat.get('room'))
Exemplo n.º 12
0
def login():
    syslog.syslog(syslog.LOG_WARNING, "Logging in to docker..")

    user_data = get_user_data()

    docker = user_data["docker"]
    auth = docker.get("auth")
    email = docker.get("email")

    if auth and email:
        home = expanduser("~")
        docker_cfg_file = open(home + "/.dockercfg", "w+")

        # TODO: Right now this truncates any other login info-- consider refactoring
        auth_hash = {"https://index.docker.io/v1/": {"auth": auth, "email": email}}

        print(json.dumps(auth_hash), file=docker_cfg_file)

        syslog.syslog(syslog.LOG_WARNING, "Successfully logged into docker as %s" % email)
Exemplo n.º 13
0
    def search_suggest(self):
        """Performs the actual suggestions-assisted search."""
        if "userid" not in session:
            return redirect(url_for('login'))

        stats = json.loads(request.form.get("stats", "[]"))
        query = request.form.get("query", None)
        perform_search = query is not None

        userid = session.get("userid")
        user = get_user_data(userid)
        task = user.get_task()
        task.append_stats(stats)
        save_user_data(user)

        context = {
            "title": "Suggestion-based search",
            "query": query,
            "results_view": url_for("results_view"),
            "autocomplete": True,
            "task": task
        }

        if perform_search:
            self.logger.info("Search: %s" % repr(query))

            results = []
            for hits in self.search_engine.search(query):
                for hit in hits:
                    score = hit.score
                    url = "%s" % hit["link"]
                    title = hit["name"]
                    description = hit["description"]
                    category = hit["category"]
                    results.append((score, url, title, description, category))

            context["results"] = sorted(results, reverse=True)

        return make_response(render_template("search.html", **context))
Exemplo n.º 14
0
    def results_view(self):
        """Performs the actual search."""
        if "userid" not in session:
            return redirect(url_for('login'))

        link = request.form.get("link", None)
        stats = json.loads(request.form.get("stats", "[]"))

        userid = session.get("userid")
        user = get_user_data(userid)
        task = user.get_task()
        task.link_found = link
        task.append_stats(stats)
        save_user_data(user)
        record = self.search_engine.select(link)

        context = {
            "finalizer_view": url_for("finalizer_view"),
            "test_view": url_for(task.view),
            "record": record,
            "task": task,
        }

        return make_response(render_template("results.html", **context))
Exemplo n.º 15
0
def get_user(update):
    if update.effective_user.is_bot:
        return None
    user_id = update.effective_user.id
    ud.read_data()
    return ud.get_user_data(user_id)
Exemplo n.º 16
0
    def __init__(self):
        global app
        QtWidgets.QWidget.__init__(self)
        app.setStyle('Fusion')

        data_file = "data.json"
        if not os.path.exists(data_file):
            name = self.getText()
            email = self.getText2()
            user_data.get_user_data(name, email)

        user = user_data.extract_data()
        directory = user['directory']
        self.program_dir = directory
        self.directory_to = 'timesheets'
        self.file_name = Clock.get_year(self) + '_timebook.xlsx'
        #self.charCount = 0

        # App window
        self.setGeometry(300, 300, 300, 180)
        self.setStyleSheet("background-color: White;")
        self.setWindowTitle("Auto Timesheet")
        self.setFixedSize(300, 180)
        self.center()

        # Widgets
        self.Promptlabel = QtWidgets.QLabel(self)
        self.Promptlabel.setGeometry(QtCore.QRect(50, 10, 200, 40))
        self.Promptlabel.move(70, 20)
        self.Promptlabel.setText("Today's work description:")
        self.Promptlabel.setObjectName("Promptlabel")
        self.Promptlabel.setFont(QFont("calibri", 13))
        self.Promptlabel.adjustSize()

        self.line = QLineEdit(self)
        self.line.move(25, 50)
        self.line.resize(250, 28)

        self.submitButton = QtWidgets.QPushButton(self)
        self.submitButton.setText("Submit")
        self.submitButton.move(107, 100)
        self.submitButton.clicked.connect(self.submit_clicked)
        self.submitButton.setFont(QFont("Calibri", 11))
        self.submitButton.setStyleSheet("QPushButton::hover"
                                      "{"
                                      "background-color : lightgrey;"
                                      "}")

        self.timeButton = QtWidgets.QPushButton(self)
        self.timeButton.setText("Back")
        self.timeButton.move(107, 130)
        self.timeButton.clicked.connect(self.back_clicked)
        self.timeButton.setFont(QFont("Calibri", 11))
        self.timeButton.setStyleSheet("QPushButton::hover"
                                        "{"
                                        "background-color : lightgrey;"
                                        "}")

        self.Status = QtWidgets.QLabel(self)
        self.Status.setGeometry(QtCore.QRect(50, 10, 200, 40))
        self.Status.move(10, 165)
        self.Status.setText(str(self.status))
        self.Status.setObjectName("Promptlabel")
        self.Status.setFont(QFont("calibri", 6))
        self.Status.adjustSize()

        self.name = QtWidgets.QLabel(self)
        self.name.setGeometry(QtCore.QRect(50, 10, 200, 40))
        self.name.move(240, 165)
        self.name.setText("made by grizzly")
        self.name.setObjectName("Promptlabel")
        self.name.setFont(QFont("calibri", 6))
        self.name.adjustSize()

        self.temp_wb = load_workbook(str(self.locate_template(self.program_dir)))
        self.wb = load_workbook(str(self.locate_timebook(self.documents_dir() + '\\Timesheets\\')))
        self.Create()
        self.active_sheet = self.wb[Clock.get_month(self)]
Exemplo n.º 17
0
import json
import re
import docker_login
from user_data import get_user_data

# Starts a docker run for a given repo
# This will effectively call `docker run <flags> <repo>:<tag>`
# This service is monitored by Upstart
# User Data
# docker.repo: Repo to run
# docker.tag: Tag of repo
# docker.flags: Flags to send to `docker run` (e.g. -p 8888:8888)

syslog.syslog(syslog.LOG_WARNING, 'Running docker container...')

user_data = get_user_data()

docker = user_data['docker']
repo = docker['repo']
tag = docker.get('tag', 'latest')
repo_with_tag = "%s:%s" % (repo, tag)

flags = docker.get('flags', [])

# Allow flags to be a string or an array
if isinstance(flags, basestring):
    flags = [flags]

flags = map(lambda flag: re.sub('-(\w)\s', r'-\1=', flag),
            flags)  # Change `-x ...` to `-x=...`
Exemplo n.º 18
0
#!/usr/bin/env python
import syslog
from user_data import get_user_data
import tempfile
from subprocess import call
import os
import stat

# Pull the init script out of user data if it exists
user_data = get_user_data()

if not user_data.get('init'):
  syslog.syslog(syslog.LOG_WARNING, 'Skipping init script (non-given)...')
  exit(0)

init_script = user_data['init'].lstrip()

if not init_script.startswith('#!'):
  syslog.syslog(syslog.LOG_WARNING, 'Skipping init script (does not start with shebang #!)...')
  exit(0)

script_file = tempfile.NamedTemporaryFile(delete=False)

try:
    script_file.write(init_script)
    script_file.close()
    os.chmod(script_file.name, stat.S_IXUSR | stat.S_IRUSR)

    # We have the file, now let's run it
    syslog.syslog(syslog.LOG_WARNING, 'Running init script (%s)...' % script_file.name)
      
Exemplo n.º 19
0
    def __init__(self):

        QtWidgets.QWidget.__init__(self)
        app.setStyle('Fusion')
        self.iconFile = 'atlogo.ico'

        self.status = " "

        data_file = "data.json"
        if not os.path.exists(data_file):
            name = self.getText()
            email = self.getText2()
            user_data.get_user_data(name, email)

        import initializer
        initializer.initialize()

        import mail
        if Clock.get_day(self) == 7:
            mail.send_mail()


        self.time_selected = 0
        user = user_data.extract_data()
        directory = user['directory']
        self.program_dir = directory
        self.directory_to = 'timesheets'
        self.file_name = Clock.get_year(self) + '_timebook.xlsx'

        self.threadpool = QThreadPool()

        # Init QSystemTrayIcon
        self.tray_icon = QSystemTrayIcon(QIcon(self.iconFile))
        self.tray_icon.show()

        # Tray menu
        show_action = QAction("Show", self)
        quit_action = QAction("Exit", self)
        hide_action = QAction("Hide", self)
        show_action.triggered.connect(self.show)
        hide_action.triggered.connect(self.hide)
        quit_action.triggered.connect(app.quit)

        tray_menu = QMenu()
        tray_menu.addAction(show_action)
        tray_menu.addAction(hide_action)
        tray_menu.addAction(quit_action)
        self.tray_icon.setContextMenu(tray_menu)
        self.tray_icon.show()

        # App window
        self.setGeometry(300, 300, 300, 180)
        self.setStyleSheet("background-color: White;")
        self.setWindowTitle("Auto Timesheet")
        self.setFixedSize(300, 180)
        self.center()

        # Widgets
        self.titlelabel = QtWidgets.QLabel(self)
        self.titlelabel.setGeometry(QtCore.QRect(50, 10, 200, 40))
        self.titlelabel.setText("")
        self.titlelabel.setPixmap(QtGui.QPixmap('CNRtitle.png'))
        self.titlelabel.setScaledContents(True)
        self.titlelabel.setObjectName("titlelabel")

        self.Label = QtWidgets.QLabel(self)
        self.Label.setText("Submission @ 16:00")
        self.Label.setAlignment(QtCore.Qt.AlignCenter)
        self.Label.move(85, 60)
        self.Label.setFont(QFont("calibri", 11))
        self.Label.adjustSize()


        self.submitButton = QtWidgets.QPushButton(self)
        self.submitButton.setText("Submit Now")
        self.submitButton.move(105, 100)
        self.submitButton.clicked.connect(self.submit_clicked)
        self.submitButton.setFont(QFont("Calibri", 11))
        self.submitButton.setStyleSheet("QPushButton::hover"
                                        "{"
                                        "background-color : lightgrey;"
                                        "}")

        self.timeButton = QtWidgets.QPushButton(self)
        self.timeButton.setText("Review")
        self.timeButton.move(107, 130)
        self.timeButton.clicked.connect(self.review_clicked)
        self.timeButton.setFont(QFont("Calibri", 11))

        self.Status = QtWidgets.QLabel(self)
        self.Status.setGeometry(QtCore.QRect(50, 10, 200, 40))
        self.Status.move(10, 165)
        self.Status.setText(str(self.status))
        self.Status.setObjectName("Promptlabel")
        self.Status.setFont(QFont("calibri", 6))
        self.Status.adjustSize()

        self.name = QtWidgets.QLabel(self)
        self.name.setGeometry(QtCore.QRect(50, 10, 200, 40))
        self.name.move(240, 165)
        self.name.setText("made by grizzly")
        self.name.setObjectName("Promptlabel")
        self.name.setFont(QFont("calibri", 6))
        self.name.adjustSize()

        self.wb = load_workbook(str(self.locate_timebook(self.documents_dir() + '\\Timesheets\\')))

        self.Create()

        self.temp_wb = load_workbook(str(self.locate_template(self.program_dir)))

        self.active_sheet = self.wb[Clock.get_month(self)]
        self.check_timebook(self.program_dir)

        self.timer()