NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

from bottle import route, run, request, debug, default_app

auth = 0

users = [
{'username': 'abdu',
'password': '1234'},
{'username': 'dgkn',
'password': '4567'}
]

games = [
{'name': 'Witcher III:Wild Hunt',
'date': 2015,
'genre': 'Role Playing Game',
'comp': 'CD Projekt',
'rate': 0,
'votenumber': 0,
'avg': 0},

{'name': 'Grand Theft Auto: V',
'date': 2013,
'genre': 'Third Person Shooter',
'comp': 'Rockstar Games',
'rate': 0,
'votenumber': 0,
'avg': 0
},

{'name': 'Life Is Strange',
'date': 2015,
'genre': 'Graphic Adventure',
'comp': 'Square Enix',
'rate': 0,
'votenumber': 0,
'avg': 0
}
]


def htmlify(title, content):
page = '<!DOCTYPE html>n'
page = page + '<html>n'
page = page + ' <head>n'
page = page + ' ' + css() + 'n'
page = page + ' <title>' + title + '</title>n'
page = page + ' <meta charset="utf-8" />n'
page = page + ' </head>n'
page = page + ' <body>n'
page = page + ' ' + header()
page = page + ' ' + content + 'n'
page = page + ' ' + footer()
page = page + ' </body>n'
page = page + '</html>n'
return page

def css():
content="""
<style>
body {
background-color:#1d304a;
color:#ffffff;}

ul{
background-color:#c74959;
text-color:#c74959;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}

li{
width:10%;
float: left;
margin-left:17%;}

li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

li a:hover {
background-color: #1d304a;
}

table {
width: 100%;
margin:5% 0% 5% 0%;
border-collapse: collapse;
}

th{
color:#c74959;
font-size:200%;
padding-bottom:1%;
}

td{
padding:3%;
font-size:120%;
border-top: 1px solid #1bb0ce;
text-align: center;
vertical-align: middle;
}

.button {
background-color: #c74959;
border: none;
color: #ffffff;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
width:120px;
margin-top:10px;
}

.button:hover {
background-color: #1d304a;
color: #ffffff;
}

.footer{
text-align:center;
vertical-align: middle;}

.para{
font-size: 120%;
margin-top:3%;
margin-left:3%;
margin-bottom:3%;
}
.a1:link {color:#c74959; background-color:transparent; text-decoration:none}
.a1:visited {color:#c74959; background-color:transparent; text-decoration:none}
.a1:hover {color:#1bb0ce; background-color:transparent; text-decoration:underline}
</style>
"""
return content

def header():
content = '<nav>n'
content = content + ' <ul>n'
content = content + ' <li><a href="/assignment3/">Home</a></li>n'
content = content + ' <li><a href="/assignment3/add">Add Game</a></li>n'
if auth == 0:
content = content + ' <li><a href="/assignment3/log">Sign in</a></li>n'
else:
content = content + ' <li><a href="/assignment3/log">Sign out</a></li>n'
content = content + ' </ul>n'
content = content + '</nav>n'
return content


def footer():
content = '<hr /> <p class="footer">Abdurrahim Uysal & Doğukan Arslan | 2016©</p>n'
return content


def list_page():
title = 'IGDB-Internet Game Database'

content = '<table>n'
content = content + ' <tr class="table1">n'
content = content + ' <th>Name</th>n'
content = content + ' <th>Releasing Year</th>n'
content = content + ' <th>Genre</th>n'
content = content + ' <th>Company</th>n'
content = content + ' <th>Rate</th>n'
content = content + ' <th></th>n'
content = content + ' </tr>n'

for game in games:
content = content + ' <tr >n'
content = content + ' <td>' + str(game['name']) + '</td>n'
content = content + ' <td>' + str(game['date']) + '</td>n'
content = content + ' <td>' + str(game['genre']) + '</td>n'
content = content + ' <td>' + str(game['comp']) + '</td>n'
content = content + ' <td>' + str(round(game['avg'], 2)) + '</td>n'
content = content + ' <td>n'
content = content + ' <form method="GET" action="/assignment3/update/' + str(game['name']) + '">n'
content = content + ' <input type="submit" value="Update" class="button"/>n'
content = content + ' </form>n'
content = content + ' <form method="GET" action="/assignment3/rate_game/' + str(game['name']) + '">n'
content = content + ' <input type="submit" value="Rate" class="button" />n'
content = content + ' </form>n'
content = content + ' </td>n'
content = content + ' </tr>n'

content = content + '</table>n'

return htmlify(title, content)



route('/assignment3/', 'GET', list_page)

def search_by_name(name, games):
for game in games:
if game['name'] == name:
return game


def rate_game(name):
title = 'IGDB - Rate Game'

global games
game = search_by_name(name, games)

content = '<form method="POST" action="/assignment3/rate_submit">n'
content = content + ' Name: <input type="text" name="name" value="' + str(game['name']) + '" readonly /><br />n'
content = content + ' <select name="rate">n'
content = content + ' <option value="1">1</option>n'
content = content + ' <option value="2">2</option>n'
content = content + ' <option value="3">3</option>n'
content = content + ' <option value="4">4</option>n'
content = content + ' <option value="5">5</option>n'
content = content + ' </select>n'
content = content + ' <input type="submit" value="Update" class="button" />n'
content = content + '</form>n'
return htmlify(title, content)


route('/assignment3/rate_game/<name>', 'GET', rate_game)


def update_page(name):
title = 'IGDB - Update Game'

global games
game = search_by_name(name, games)
if (auth == 1):
content = '<form method="POST" action="/assignment3/update_submit">n'
content = content + ' Name: <input type="text" name="name" value="' + str(
game['name']) + '" readonly /><br />n'
content = content + ' Releasing Year: <input type="number" name="date" value=' + str(
game['date']) + ' /><br />n'
content = content + ' Genre: <input type="checkbox" name="genre" value="RPG" /> RPG <input type="checkbox" name="genre" value="TPS" /> TPS<input type="checkbox" name="genre" value="Adventure" /> Adventure<input type="checkbox" name="genre" value="RTS" /> RTS<input type="checkbox" name="genre" value="Simulation" /> Simulation'+ ' <br />n'
content = content + ' Company: <input type="text" name="comp" value="' + str(
game['comp']) + '" /><br />n'
content = content + ' <input type="submit" value="Update" class="button" />n'
content = content + '</form>n'
else:
content = """
<p class="para">Please <a class="a1" href="/assignment3/log">sign in</a> first.</p>
"""
return htmlify(title, content)


route('/assignment3/update/<name>', 'GET', update_page)


def rate_submit():
title = 'IGDB - Update Game'

post_request = request.POST
name = str(post_request['name'])
rate = int(str(post_request['rate']))

global games
game = search_by_name(name, games)
game['name'] = name
rate1 = float(str(game['rate']))

final_rate = (rate1 + rate)
game['rate'] = str(int(final_rate))
game['votenumber'] = game['votenumber'] + 1
game['avg'] = float(float(game['rate']) / game['votenumber'])
content = '<p class="para">Rated the following game:</p>n'
content = content + '<table>n'
content = content + ' <tr>n'
content = content + ' <th>Name</th>n'
content = content + ' </tr>n'
content = content + ' <tr>n'
content = content + ' <td>' + str(name) + '</td>n'
content = content + ' <td>' + str(rate) + '</td>n'
content = content + ' </tr>n'
content = content + '</table>n'

return htmlify(title, content)


route('/assignment3/rate_submit', 'POST', rate_submit)


def update_submit_page():
title = 'IGDB - Update Game'

post_request = request.POST

name = str(post_request['name'])
date = int(post_request['date'])
genre = str(post_request['genre'])
comp = str(post_request['comp'])

global games
game = search_by_name(name, games)
game['name'] = name
game['date'] = date
game['genre'] = genre
game['comp'] = comp

content = '<p class="para">Updated the following game:</p>n'
content = content + '<table>n'
content = content + ' <tr>n'
content = content + ' <th>Name</th>n'
content = content + ' <th>Releasing Year</th>n'
content = content + ' <th>Genre</th>n'
content = content + ' <th>Company</th>n'
content = content + ' </tr>n'
content = content + ' <tr>n'
content = content + ' <td>' + str(name) + '</td>n'
content = content + ' <td>' + str(date) + '</td>n'
content = content + ' <td>' + str(genre) + '</td>n'
content = content + ' <td>' + str(comp) + '</td>n'
content = content + ' </tr>n'
content = content + '</table>n'

return htmlify(title, content)


route('/assignment3/update_submit', 'POST', update_submit_page)


def add_page():
title = 'IGDB - Add Game'

if (auth == 1):
content = '<form method="POST" action="/assignment3/add_submit">n'
content = content + ' Name: <input type="text" name="name" /><br />n'
content = content + ' Releasing Year: <input type="number" name="date" /><br />n'
content = content + ' Genre: <input type="checkbox" name="genre" value="RPG" /> RPG <input type="checkbox" name="genre" value="TPS" /> TPS<input type="checkbox" name="genre" value="Adventure" /> Adventure<input type="checkbox" name="genre" value="RTS" /> RTS<input type="checkbox" name="genre" value="Simulation" /> Simulation<br />n'
content = content + ' Company: <input type="text" name="comp" /><br /><br/>n'
content = content + ' <input type="submit" value="Add" class="button"/>n'
content = content + '</form>n'
else:
content = """
<p class="para">Please <a class="a1"href="/log">sign in</a> first.</p>
"""

return htmlify(title, content)


route('/assignment3/add', 'GET', add_page)


def add_submit_page():
title = 'IGDB - Add Game'

post_request = request.POST

genre = ""

name = str(post_request['name'])
date = int(post_request['date'])
if str(post_request['genre']) != "RPG":
genre = genre + "RPG "
if str(post_request['genre']) != "":
genre = genre + "TPS "
if str(post_request['genre']) != "":
genre = genre + "Adventure "
if str(post_request['genre']) != "":
genre = genre + "RTS "
if str(post_request['genre']) != "":
genre = genre + "Simulation "

comp = str(post_request['comp'])

global games
games = games + [{'name': name, 'date': date, 'genre': genre, 'comp': comp, 'rate': 0, 'votenumber': 0, 'avg': 0}]

content = '<p class="para">Added the following game:</p>n'
content = content + '<table>n'
content = content + ' <tr>n'
content = content + ' <th>Name</th>n'
content = content + ' <th>Releasing Year</th>n'
content = content + ' <th>Genre</th>n'
content = content + ' <th>Company</th>n'
content = content + ' </tr>n'
content = content + ' <tr>n'
content = content + ' <td>' + str(name) + '</td>n'
content = content + ' <td>' + str(date) + '</td>n'
content = content + ' <td>' + str(genre) + '</td>n'
content = content + ' <td>' + str(comp) + '</td>n'

content = content + ' </tr>n'
content = content + '</table>n'
return htmlify(title, content)


def log_page():
if auth==0:
content = '''
<form action="/assignment3/autho" method="POST">
Username: <input name="username" type="text" />
</br>
Password: <input name="password" type="password" />
</br>
<input value="Login" type="submit" class="button"/>
</form>
'''
return htmlify("Login", content)
else:
auth==0

content="""<p class="para">You have succesfully sign out.</p><a class="a1" href="/assignment3/">Go to main page!</a>"""
return htmlify("Login", content)

def autho():

global auth
global auth2
post_request = request.POST
username = str(post_request['username'])
pass_code = str(post_request['password'])

for user in users:
if (str(user['username']) == username and str(user['password']) == pass_code):
auth = 1

if (auth == 1):
content = """
<p class="para">Acces granted.</p><a class="a1" href="/assignment3/">Go to main page!</a>"""
else:
content = """<p class="para">Acces Denied.<a class="a1" href="/log">Try again!</a></p>"""
return htmlify("Login Result", content)


route('/assignment3/autho', 'POST', autho)
route('/assignment3/add_submit', 'POST', add_submit_page)
route('/assignment3/log', 'GET', log_page)

# This line makes bottle give nicer error messages
debug(True)
# This line is necessary for running on PythonAnywhere
application = default_app()
# The below code is necessary for running this bottle app standalone on your computer.
if __name__ == "__main__":
run()

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.