Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
__pycache__

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# WebMoney
To start write command:
/venv/bin/python -m flask run
35 changes: 35 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from flask import Flask, render_template, request
import random
import json
import crawler

app = Flask(__name__)


@app.route('/')
def hello_world():
currency = crawler.get_value()
return render_template("main.html", currency=currency)


@app.route('/game/')
def guess_currency():
currency = crawler.get_value()
random.shuffle(currency)
return render_template("game.html", value=currency[0])


@app.route('/game/answer', methods=['GET', 'POST'])
def check_answer():
form = request.args
currency = form['currency']
ans = form['ans']
print(type(ans))
data = {}
data['currency'] = currency
data['name'] = ans
return render_template("answer.html",data=data )


if __name__ == '__main__':
app.run()
3 changes: 3 additions & 0 deletions check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import crawler
value = crawler.get_value()
print(value[0]['count'])
27 changes: 27 additions & 0 deletions crawler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import requests
from bs4 import BeautifulSoup
import re
import json
def get_value():
link = "http://cbr.ru/currency_base/daily"
responce = requests.get(link)
soup = BeautifulSoup(responce.text, 'html.parser')
p = []
for i in soup.find_all('td'):
p.append(i)
count = 2
currency = []
while count <= len(p):
d = {}
d["count"] = int(p[count].string)
count += 1
d["currency_name"] = p[count].string
count += 1
d["currency"] = float(p[count].string.replace(',','.'))
count += 3
currency.append(d)

with open("currency.txt", "w") as f:
for i in currency:
f.write(json.dumps(i, ensure_ascii=False) + "\n")
return currency
34 changes: 34 additions & 0 deletions currency.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{"count": 1, "currency_name": "Австралийский доллар", "currency": 58.2872}
{"count": 1, "currency_name": "Азербайджанский манат", "currency": 44.1188}
{"count": 100, "currency_name": "Армянских драмов", "currency": 14.4022}
{"count": 1, "currency_name": "Белорусский рубль", "currency": 29.261}
{"count": 1, "currency_name": "Болгарский лев", "currency": 46.2331}
{"count": 1, "currency_name": "Бразильский реал", "currency": 13.7874}
{"count": 100, "currency_name": "Венгерских форинтов", "currency": 24.9066}
{"count": 1000, "currency_name": "Вон Республики Корея", "currency": 67.3775}
{"count": 10, "currency_name": "Гонконгских долларов", "currency": 96.5715}
{"count": 1, "currency_name": "Датская крона", "currency": 12.1608}
{"count": 1, "currency_name": "Доллар США", "currency": 74.9578}
{"count": 1, "currency_name": "Евро", "currency": 90.4666}
{"count": 10, "currency_name": "Индийских рупий", "currency": 10.0429}
{"count": 100, "currency_name": "Казахстанских тенге", "currency": 17.4521}
{"count": 1, "currency_name": "Канадский доллар", "currency": 60.3817}
{"count": 100, "currency_name": "Киргизских сомов", "currency": 88.3653}
{"count": 1, "currency_name": "Китайский юань", "currency": 11.5569}
{"count": 10, "currency_name": "Молдавских леев", "currency": 41.9607}
{"count": 1, "currency_name": "Новый туркменский манат", "currency": 21.4472}
{"count": 10, "currency_name": "Норвежских крон", "currency": 90.2497}
{"count": 1, "currency_name": "Польский злотый", "currency": 19.8411}
{"count": 1, "currency_name": "Румынский лей", "currency": 18.3599}
{"count": 1, "currency_name": "СДР (специальные права заимствования)", "currency": 107.7196}
{"count": 1, "currency_name": "Сингапурский доллар", "currency": 56.508}
{"count": 10, "currency_name": "Таджикских сомони", "currency": 65.7236}
{"count": 10, "currency_name": "Турецких лир", "currency": 90.7161}
{"count": 10000, "currency_name": "Узбекских сумов", "currency": 71.0623}
{"count": 10, "currency_name": "Украинских гривен", "currency": 26.9984}
{"count": 1, "currency_name": "Фунт стерлингов Соединенного королевства", "currency": 104.0189}
{"count": 10, "currency_name": "Чешских крон", "currency": 34.9568}
{"count": 10, "currency_name": "Шведских крон", "currency": 89.1114}
{"count": 1, "currency_name": "Швейцарский франк", "currency": 81.7692}
{"count": 10, "currency_name": "Южноафриканских рэндов", "currency": 52.3266}
{"count": 100, "currency_name": "Японских иен", "currency": 69.178}
24 changes: 24 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
body{
font-family: "Lato Hairline", Helvetica, Arial, sans-serif;
background-color: honeydew;
color: #29ff00;
}
h1{
text-align: center;
color: blueviolet;
}
table{;
width: auto;
}
thead td{
font-weight: bold;
border-bottom: solid darkblue;
}
tbody tr:nth-child(odd){
background-color: darkslateblue;
}

tbody tr:nth-child(even){
background-color: #ff0026;
}

27 changes: 27 additions & 0 deletions templates/answer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/static/style.css">
</head>
<body>
{% if data['name'] == data['currency'] %}
<p>Молодец</p>

<form action="/game">

<p><input type="submit" value="Еще разок?"></p>
</form>
{% endif %}
{% if data['currency'] != data['name'] %}
<p>Мимо, правильный ответ: '{{ data['currency']}}'</p>

<form action="/game">

<p><input type="submit" value="Сейчас точно повезет"></p>
</form>
{% endif %}


</body>
</html>
27 changes: 27 additions & 0 deletions templates/game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/static/style.css">
</head>
<body>
<h1> А ты знаешь ему цену?</h1>

<form action="/game/answer">
<label>{{
value['currency']

}} рублей стоит {{ value['count'] }} </label> <input
name="ans"
type="text"
>
<label> </label>
<input type="hidden" , name=
"currency" , value=
"{{ value['currency_name'] }}">

<p><input type="submit" value="да"></p>
</form>

</body>
</html>
35 changes: 35 additions & 0 deletions templates/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/static/style.css">
</head>
<body>
<h1> Курс валюты на сегодня</h1>

<form action="/game">

<p><input type="submit" value="Поиграем?"></p>
</form>
<table>
<tread>
<tr>
<td>Рубль</td>
<td>Валюта</td>
<td>Единиц</td>
<td>Курс</td>
</tr>
</tread>
{% for value in currency %}
<tr>
<td>Рубль</td>
<td>{{value['count']}}</td>
<td>{{value['currency_name']}}</td>
<td>{{value['currency']}}</td>
</tr>
{% endfor %}


</table>
</body>
</html>
76 changes: 76 additions & 0 deletions venv/bin/activate
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r
fi

if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
unset _OLD_VIRTUAL_PS1
fi

unset VIRTUAL_ENV
if [ ! "$1" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="/home/lepad/Desktop/proga/WebMoney/venv"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH

# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
if [ "x(venv) " != x ] ; then
PS1="(venv) ${PS1:-}"
else
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
fi
fi
export PS1
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r
fi
37 changes: 37 additions & 0 deletions venv/bin/activate.csh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This file must be used with "source bin/activate.csh" *from csh*.
# You cannot run it directly.
# Created by Davide Di Blasi <davidedb@gmail.com>.
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>

alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate'

# Unset irrelevant variables.
deactivate nondestructive

setenv VIRTUAL_ENV "/home/lepad/Desktop/proga/WebMoney/venv"

set _OLD_VIRTUAL_PATH="$PATH"
setenv PATH "$VIRTUAL_ENV/bin:$PATH"


set _OLD_VIRTUAL_PROMPT="$prompt"

if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
if ("venv" != "") then
set env_name = "venv"
else
if (`basename "VIRTUAL_ENV"` == "__") then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
set env_name = `basename \`dirname "$VIRTUAL_ENV"\``
else
set env_name = `basename "$VIRTUAL_ENV"`
endif
endif
set prompt = "[$env_name] $prompt"
unset env_name
endif

alias pydoc python -m pydoc

rehash
Loading