forked from Akin-Net/aa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaa.py
executable file
·87 lines (73 loc) · 2.34 KB
/
aa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Cliente para enviar mensagens ao servidor
# http://wiki.nosdigitais.teia.org.br/AA_0.0.1
import urllib, urllib2
import sys
import os
from time import time, strftime
from threading import Timer
instrucoes = """
AA
Using:
aa start = starts the work session of the day
aa alert <resumo> = alerts what he is doing now
aa stop = stops the work session of the day
"""
def comeca():
"""Start the session"""
home = os.getenv("HOME")
f = open(home+"/.aa.txt", "w")
f.close()
def termina():
"""Stop the session"""
home = os.getenv("HOME")
f = open(home+"/.aa.txt", "r")
str = f.readline()
while (len(str) > 0):
# prepare the string
str = str.split('\n')
str = str[0].split(',')
msg = {'user': os.getenv('NICKNAME'), 'log': str[0]+'::'+str[1]}
dados = urllib.urlencode(msg)
# sends the string
req = urllib2.Request('http://nightsc.com.br/aa/novo_log.php', dados)
res = urllib2.urlopen(req)
pagina = res.read()
str = f.readline()
res.close()
def direciona(args):
"""Parse AA arguments"""
#talvez usar o argparse?
if args[0] in ['start','inicio', 'inicia', 'início', 'begin']:
comeca()
log('start')
print '[AA] Your session has started. Happy hacking!'
elif args[0] in ['stop','fim', 'finaliza', 'termina', 'end']:
# registra hora de fim
log('stop')
termina()
print '[AA] You ended the sesssion and published at http://nightsc.com.br/aa. CYA!'
elif args[0] in ['alert','informa', 'marca', 'anota', 'msg'] and args[1]:
# registra marca no registro iniciado (corrente)
#FIXME só funciona se a mensagem estiver entre parenteses:
log("alert "+sys.argv[2:][0])
print '[AA] New alert: "%s" logged.' % sys.argv[2:][0]
else:
print 'Opção "%s" inválida!' % args[0]
def log(msg):
"""Saves messages on the ~/.aa.txt temp file"""
home = os.getenv('HOME')
f = open(home+"/.aa.txt","a")
try:
#escreve mensagem no arquivo com data/hora
#FIXME definir melhor formato para data/hora
f.writelines(strftime("%d-%m-%y %H-%M-%S")+","+msg+"\n")
finally:
f.close()
return
if __name__=="__main__":
if len(sys.argv) > 1:
direciona(sys.argv[1:])
else:
print instrucoes