Ejemplo n.º 1
0
 def is_admin(self):
     """
         Indicate if this user is admin
         
         :rtype: bool
     """
     return str(self._user_id) in config(
     )["group"]["admin"] or self._user_id in config()["group"]["admin"]
Ejemplo n.º 2
0
    def debug(self, text):
        """
            Display debug information on console

            :param text: Information to display
            :type text: str
        """
        debug_text = "[" + str(self.id()) + "] " + text
        if config()["debug_send"] >= 1:
            print(debug_text)
        if config()["debug_send"] >= 2:
            for uid in config()["group"]["debug"]:
                updater().bot.send_message(chat_id=uid,
                                           text="```\n" + debug_text + "\n```",
                                           parse_mode="Markdown")
Ejemplo n.º 3
0
 def save(self):
     """
         Save user's data on disk
     """
     os.makedirs(config()["database_directory"] + DIR_DB_PICKLE,
                 exist_ok=True)
     file = open(self._filename, 'wb')
     pickle.dump(self._data, file)
Ejemplo n.º 4
0
    def get_timetable_ics(self,
                          id,
                          type,
                          year=None,
                          trimester=None,
                          force=False):
        """
            Get ICS file.
            File in cache is used if possible.

            :param year: Year of timetable
            :type year: int

            :param trimester: Trimester of timetable
            :type trimester: int

            :param id: id of entity
            :type id: int

            :param type: type of entity
            :type type: int

            :param force: Force download and update cache
            :type force: bool
        """
        from heig.init import config
        from heig.init import BOT_VERSION
        dirname = config(
        )["database_directory"] + DIR_DB_TIMETABLE + "/" + str(
            year) + "/" + str(trimester) + "/" + str(type)
        filename = dirname + "/" + str(id) + ".ics"
        download = force or not os.path.isfile(filename)
        os.makedirs(dirname, exist_ok=True)
        if download:
            if not self.is_registred():
                raise GapsError("You are not registred")
            params = {'type': type, 'id': id, 'icalendarversion': 2}
            if year is not None:
                params['annee'] = year
            if trimester is not None:
                params['trimestre'] = trimester

            ics = requests.get(URL_TIMETABLE,
                               headers={
                                   "User-Agent":
                                   "HEIG-Bot (" + BOT_VERSION + ")"
                               },
                               auth=(self._data['username'],
                                     self._data['password']),
                               params=params).text
            file = open(filename, "w")
            file.write(ics)
            file.close()
        else:
            file = open(filename, "r")
            ics = file.read()
            file.close()
        return ics
Ejemplo n.º 5
0
    def __init__(self, user_id):
        """
            Initialize User object, and if possible load user's data

            :param user_id: Telegram userid
            :type user_id: 
        """
        self._user_id = user_id
        self._filename = config()["database_directory"] + DIR_DB_PICKLE + str(
            self._user_id) + ".pickle"
        if (os.path.isfile(self._filename)):
            file = open(self._filename, 'rb')
            self._data = pickle.load(file)
        else:
            self._data = {}
Ejemplo n.º 6
0
    This file is part of heig-bot.

    heig-bot is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    heig-bot is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with heig-bot. If not, see <https://www.gnu.org/licenses/>.
"""
import os

from heig.init import config
from heig.user import User, DIR_DB_PICKLE

for i in os.scandir(config()["database_directory"] + DIR_DB_PICKLE):
    id = i.name[:-7]
    user = User(id)
    try:
        user.gaps().check_gaps_notes(id, auto=True)
    except:
        print("Error for " + id)

#for id in config["logs_userid"]:
#updater.bot.send_message(chat_id=id, text="Bonjour")