Skip to content

Commit 9264dd7

Browse files
authored
Merge pull request #211 from micumatei/tw/lab5
Tw/lab5
2 parents 4cb483a + 546ae6c commit 9264dd7

File tree

7 files changed

+204
-0
lines changed

7 files changed

+204
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
##Tuxy-Bot
2+
3+
Tuxy Pinguinescu are nevoie de o unealtă web care să îi ușureze munca de zi cu zi.
4+
Pentru că nimeni din echipa lui Tuxy nu este suficient de pregătit pentru a dezvolta **Tuxy Bot** această sarcină îți revine ție.
5+
6+
Tuxy Bot trebuie să știe să rezolve următoarele sarcini:
7+
8+
- /reține cheie valoare
9+
- Se va salva această informație și în toate comenzile ce vor fi trimise ulterior se va schimba orice apariție a cuvântului *cheie* cu valoarea acestuia
10+
- /palindrom valoare
11+
- Verifică dacă valoarea primită este un șir palindrom
12+
- /calculează valoare1 operator valoare2
13+
- /evaluează expresie
14+
- /curăță
15+
- Șterge toate informațiile salvate până în acest moment
16+
17+
Câteva exemple:
18+
19+
```
20+
/reține acasă Iași
21+
Am învățat termenul `acasă`.
22+
23+
/reține expresie 20 + 4 - 3 * 8
24+
Am învățat termenul `expresie`.
25+
26+
/evaluează expresie
27+
Rezultatul expresiei: '20 + 4 - 3 * 8' este 0
28+
29+
/palindrom acasa
30+
Șirul 'Iași' nu este palindrom.
31+
32+
/curăță
33+
Am șters toate informațiile din această sesiune.
34+
``
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"""
2+
Tuxy bot.
3+
"""
4+
5+
# pylint: disable=import-error, no-member
6+
import cherrypy
7+
8+
9+
class TuxyBot(object):
10+
"""Tuxy Bot."""
11+
12+
@cherrypy.expose
13+
@staticmethod
14+
def index():
15+
"""Dummy Index Page."""
16+
return "OK"
17+
18+
@cherrypy.expose
19+
@staticmethod
20+
def retine(key, value):
21+
"""Register a key value pair."""
22+
cherrypy.session[key] = value
23+
# NOTE(mmicu): This is just an example, we should not expose this data
24+
# TODO(mmicu): It might be a good idea to have a new dict inside
25+
# the session that stors only KVP's for this app
26+
return repr(cherrypy.session.items())
27+
28+
@cherrypy.expose
29+
@staticmethod
30+
def palindrom(value=None):
31+
"""Check if a string is palindrome."""
32+
if not value:
33+
return "The value can't be None."
34+
for key, value in cherrypy.session.items():
35+
value.replace(key, value)
36+
return str(value == value[::-1])
37+
38+
@cherrypy.expose
39+
@staticmethod
40+
def calculeaza(val1, operator, val2):
41+
"""Solve an equation Grade 1."""
42+
for key, value in cherrypy.session.items():
43+
val1 = val1.replace(key, value)
44+
operator = operator.replace(key, value)
45+
val2 = val2.replace(key, value)
46+
47+
try:
48+
if operator == "+":
49+
return str(int(val1) + int(val2))
50+
elif operator == "-":
51+
return str(int(val1) - int(val2))
52+
elif operator == "*":
53+
return str(int(val1) * int(val2))
54+
elif operator == "/":
55+
return str(int(val1) / int(val2))
56+
except ValueError:
57+
return "Respecta constrangerile pentru: {} {} {}".format(
58+
val1, operator, val2)
59+
except ZeroDivisionError:
60+
return "Div by zero"
61+
62+
@cherrypy.expose
63+
@staticmethod
64+
def curata():
65+
"""Clean the sessin."""
66+
cherrypy.session.clear()
67+
68+
69+
def main():
70+
"""Main."""
71+
conf = {
72+
"/": {
73+
'tools.sessions.on': True,
74+
}
75+
}
76+
cherrypy.quickstart(TuxyBot(), "/", conf)
77+
78+
79+
if __name__ == "__main__":
80+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cherrypy
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Tuxy captcha
2+
3+
Tuxy are nevoie de un mecanism care să îi garanteze că toți utilizatorii aplicației lui știu să rezolve ecuații de gradul I.
4+
5+
Pentru că specialiștii din echipa lui Tuxy nu au reușit să rezolve această problemă au apelat la tine. Pentru că este o problemă destul de urgentă ai la dispoziție doar 75 de minute să rezolvi această sarcină.
6+
7+
Exemple:
8+
- 10 - 3x = 1
9+
- 6x * 7 = 42
10+
- 10x - 4 * 2 = 1
11+
12+
Funcții ce ar putea fi utile:
13+
- [explode](https://secure.php.net/manual/en/function.explode.php)
14+
- [intval](https://secure.php.net/manual/en/function.intval.php)
15+
- [strpos](https://secure.php.net/manual/en/function.strpos.php)
16+
17+
Mai multe detalii pot fi găsite în [documentație](https://secure.php.net/manual/en/).
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Tuxy</title>
7+
link
8+
</head>
9+
<body>
10+
<form action="#" method="POST" accept-charset="utf-8">
11+
<label for="first"></label><input type="text" name="first" value="0" id="firstfirst">X +
12+
<label for="second"></label><input type="text" name="second" value="0" id="second">=
13+
<label for="rez"></label><input type="text" name="rez" value="0" id="rez">
14+
<p><input type="submit" value="Continue →"></p>
15+
</form>
16+
<p>Rezultat: {}</p>
17+
</body>
18+
</html>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Tuxy captcha.
3+
"""
4+
# pylint: disable=import-error, no-member, invalid-name
5+
import cherrypy
6+
7+
8+
def get_data(filename):
9+
"""Get data from a file."""
10+
with open(filename, 'r') as data:
11+
return data.read()
12+
13+
14+
class TuxyCaptcha(object):
15+
"""TuxyCaptcha."""
16+
exposed = True
17+
18+
@staticmethod
19+
def GET():
20+
"""GET method."""
21+
return get_data("index.html").format("")
22+
23+
@staticmethod
24+
def POST(first, second, rez):
25+
"""POST method."""
26+
try:
27+
# x + y = z
28+
# (z - y)/x
29+
val_x = float(first)
30+
val_y = float(second)
31+
val_z = float(rez)
32+
response = get_data("index.html").format((val_z-val_y)/val_x)
33+
except ValueError:
34+
return get_data("index.html").format("Parametri prosti")
35+
except ZeroDivisionError:
36+
return get_data("index.html").format(
37+
"Coeficientul lui x este 0 => x nu are o valoare exacta.")
38+
else:
39+
return response
40+
41+
42+
def main():
43+
"""Main."""
44+
conf = {
45+
"/": {
46+
'request.dispatch': cherrypy.dispatch.MethodDispatcher()
47+
}
48+
}
49+
cherrypy.quickstart(TuxyCaptcha(), "/", conf)
50+
51+
52+
if __name__ == "__main__":
53+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cherrypy

0 commit comments

Comments
 (0)