Created
July 30, 2024 12:35
-
-
Save ZiTAL/92f8891c9466a1b5c66cc5d0196e6372 to your computer and use it in GitHub Desktop.
tortolika.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
# apt-get install python3-pyqt5 python3-lxml | |
# | |
# gutxienezko parametroak: python3 tortolika.py -u erabiltzailea -p pasahitza | |
# tray barik: python3 tortolika.py -u erabiltzailea -p pasahitza -nt | |
# desktop barik: python3 tortolika.py -u erabiltzailea -p pasahitza -nd | |
# minuturo galdetu: python3 tortolika.py -u erabiltzailea -p pasahitza -i 60000 | |
from PyQt5.QtWidgets import QMainWindow, QApplication, QSystemTrayIcon, QMenu | |
from PyQt5.QtGui import QIcon | |
from PyQt5.QtCore import Qt, QTimer | |
from tempfile import NamedTemporaryFile | |
from base64 import b64decode | |
from urllib.parse import urlencode | |
from io import BytesIO | |
from pycurl import Curl, COOKIEJAR, COOKIEFILE, FOLLOWLOCATION, REFERER, USERAGENT, SSL_VERIFYPEER, SSL_VERIFYHOST | |
from lxml import etree | |
from datetime import datetime | |
from re import match, search | |
from time import time, mktime | |
from sys import argv, exit | |
class Window(QMainWindow): | |
def __init__(self, argv): | |
# QMainWindow-en construct-a | |
super(Window, self).__init__() | |
# kontsolatik bidali dizkiogun parametroak programan sartu | |
self._parseArgv(argv) | |
# focus mota teklatu eta saguarenak aukeratzen ditugu | |
self.setFocusPolicy(Qt.StrongFocus) | |
self._initUI() | |
def _parseArgv(self, argv): | |
self._credentials = {} | |
self._interval = 1000 * 60 * 60 | |
self._tray = True | |
self._desktop = True | |
i = 0 | |
for arg in argv: | |
if argv[i]=='-u' or argv[i]=='--user': | |
self._credentials['user'] = argv[i+1] | |
if argv[i]=='-p' or argv[i]=='--password': | |
self._credentials['passwd'] = argv[i+1] | |
if argv[i]=='-i' or argv[i]=='--interval': | |
self._interval = eval(argv[i+1]) | |
if argv[i]=='-nt' or argv[i]=='--no-tray': | |
self._tray = False | |
if argv[i]=='-nd' or argv[i]=='--no-desktop': | |
self._desktop = False | |
i = i + 1 | |
if 'user' not in self._credentials or 'passwd' not in self._credentials: | |
self._help() | |
if self._tray == False and self._desktop == False: | |
print('Tray or Desktop option required') | |
self._help() | |
def _initUI(self): | |
# tray-a jarri | |
self._trayUI() | |
# interval parametroan sartu dugun aldiro informazioa eguneratu | |
self._setTimer() | |
# kargatzerakoan datuak hartu | |
self._updateInfo() | |
# desktop aplikazioa jarri | |
self._desktopUI() | |
def _trayUI(self): | |
if self._tray: | |
# ikonoarentzako aldi baterako fitxategi batean sartuko dugu | |
fp = NamedTemporaryFile(delete=True) | |
fp.write(self._getIcon()) | |
# ikonoa fitxategia denean, guk base64-n daukagu | |
# self.tray_icon = SystemTrayIcon(QtGui.QIcon('favicon3.png'), self) | |
#self.tray_icon = QSystemTrayIcon(QIcon(fp[1]), self) | |
self.tray_icon = QSystemTrayIcon(QIcon(fp.name), self) | |
# ikonoa sortu eta gero ezabatu | |
fp.close() | |
# menua sortu | |
self._setMenu() | |
# tray_icon-ean click/right click egiterakoan sortzen den ebentoa | |
self.tray_icon.activated.connect(self._iconActivated) | |
# tray-a erakutsi | |
self.tray_icon.show() | |
def _desktopUI(self): | |
if self._desktop: | |
fp = NamedTemporaryFile(delete=True) | |
fp.write(self._getIcon()) | |
self.setWindowIcon(QIcon(fp.name)) | |
fp.close() | |
self.showMinimized() | |
# ikonoa base64-n enkodeatu | |
def _getIcon(self): | |
img = 'iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAAG0OVFdAAAABGdBTUEAALGPC/xhBQAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB+EBBAobEW3fst4AAABBdEVYdENvbW1lbnQAQ1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gODA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eO/38qAGeX1NxaiQAAAABJRU5ErkJggg==' | |
img64 = b64decode(img) | |
return img64 | |
def _setMenu(self): | |
menu = QMenu() | |
# action_refresh = menu.addAction("Refresh") | |
# action_refresh.triggered.connect(_updateInfo)) | |
action_exit = menu.addAction('Exit') | |
action_exit.triggered.connect(exit) | |
self.tray_icon.setContextMenu(menu) | |
def _iconActivated(self, reason): | |
if reason == 1: | |
# right click | |
pass | |
elif reason == 3: | |
# left click | |
self._updateInfo() | |
pass | |
def _setTimer(self): | |
self.timer = QTimer() | |
self.timer.timeout.connect(self._updateInfo) | |
self.timer.start(self._interval) | |
def _updateInfo(self): | |
t = TortolikaCurl(self._credentials) | |
result = t.getInfo() | |
if result['STATUS'] == 'ERROR': | |
txt = result['STATUS_TEXT'] | |
else: | |
txt = result['H']+":"+result['M'] | |
if self._tray: | |
self.tray_icon.showMessage('Tortolika', txt) | |
if self._desktop: | |
self.setWindowTitle("Tortolika: "+txt) | |
def _help(self): | |
h = """ | |
Tortolika: | |
Required arguments: | |
-u, --user username | |
-p, --password password | |
Optional arguments: | |
-i, --interval time to refresh in miliseconds | |
-nd, --no-desktop no desktop application | |
-nt, --no-tray no tray application | |
""" | |
print(h) | |
exit() | |
def focusInEvent(self, event): | |
self.showMinimized() | |
self._updateInfo() | |
class TortolikaCurl(): | |
def __init__(self, credentials): | |
self._credentials = credentials | |
def getInfo(self): | |
result = {} | |
result['STATUS'] = 'ERROR' | |
html = self._login() | |
tree = etree.HTML(html) | |
date = datetime.now().strftime("%Y/%m/%d") | |
b = tree.xpath("//span[@class=\"NegritaNegro12\" and .= \""+date+"\"]/../span[@class=\"NormalNegro12\"]/b") | |
if len(b)<1: | |
result['STATUS_TEXT'] = 'E_LOGIN' | |
else: | |
m = match('^t\s([0-9]{2}):([0-9]{2})$', b[0].text) | |
if m != None: | |
total = {} | |
total['H'] = m.group(1) | |
total['i'] = m.group(2) | |
total_seconds = int(total['H']) * 3600 + int(total['i']) * 60 | |
span = tree.xpath("//span[@class=\"NegritaNegro12\" and .= \""+date+"\"]/../span[@class=\"NormalAzul12\"]") | |
i = len(span)-1 | |
m = search('^([0-9]{2}):([0-9]{2})', span[i].text) | |
if m != None: | |
now = datetime.now() | |
denbora = {} | |
denbora['Y'] = now.strftime('%Y') | |
denbora['m'] = now.strftime('%m') | |
denbora['d'] = now.strftime('%d') | |
denbora['H'] = m.group(1) | |
denbora['M'] = m.group(2) | |
# timestamp | |
now = int(time()) | |
# create date | |
a = datetime(int(denbora['Y']), int(denbora['m']), int(denbora['d']), int(denbora['H']), int(denbora['M']), 0, 0) | |
# date to timestamp | |
last_connect = int(mktime(a.timetuple())) | |
total = total_seconds + now - last_connect | |
result['STATUS'] = 'OK' | |
result['H'] = int(total / 3600) | |
result['M'] = int(total % 3600 / 60) | |
if result['H']<10: | |
result['H'] = "0"+str(result['H']) | |
if result['M']<10: | |
result['M'] = "0"+str(result['M']) | |
result['H'] = str(result['H']) | |
result['M'] = str(result['M']) | |
else: | |
result['STATUS_TEXT'] = 'E_UNKNOW' | |
else: | |
result['STATUS_TEXT'] = 'E_UNKNOW' | |
return result | |
def _login(self): | |
# denbora baterako fitxategia cookie-ak sartzeko | |
fp = NamedTemporaryFile(delete=True) | |
# set cookie | |
params = {} | |
params['Modo'] = 'Balidatu' | |
params['erabiltzailea'] = self._credentials['user'] | |
params['pasahitza'] = self._credentials['passwd'] | |
params['rutaValidacion'] = '/Default.asp?' | |
params['Destino'] = '' | |
params['selModulo'] = '' | |
params['Hizkuntza'] = 'Euskera' | |
params['cmdAldatu'] = 'Aldatu»' | |
params['cmdSartu'] = 'Sartu»' | |
postfields = urlencode(params) | |
url = 'https://tortolika.eitb.lan/menu/bd_Erabiltzailea.asp?'+postfields | |
buffer = BytesIO() | |
c = Curl() | |
c.setopt(SSL_VERIFYPEER, 0) | |
c.setopt(SSL_VERIFYHOST, 0) | |
c.setopt(c.URL, url) | |
c.setopt(FOLLOWLOCATION, True) | |
c.setopt(REFERER, 'http://tortolika/') | |
c.setopt(USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko') | |
c.setopt(COOKIEJAR, fp.name) | |
c.setopt(c.WRITEDATA, buffer) | |
c.perform() | |
c.close() | |
# use credentials cookie and get the body | |
buffer = BytesIO() | |
c = Curl() | |
c.setopt(SSL_VERIFYPEER, 0) | |
c.setopt(SSL_VERIFYHOST, 0) | |
c.setopt(c.URL, 'https://tortolika.eitb.lan/kalitatea/Mod_SSE/euskera/fichajes2.asp') | |
c.setopt(COOKIEFILE, fp.name) | |
c.setopt(c.WRITEDATA, buffer) | |
c.perform() | |
body = buffer.getvalue() | |
body = body.decode('windows-1252') | |
# cookie-ak gordetzeko fitxategia ezabatu | |
fp.close() | |
return body | |
if __name__ == '__main__': | |
app = QApplication([]) | |
w = Window(argv) | |
exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment