Last active
August 5, 2020 13:57
-
-
Save avielb/57cf2e1abb60c070e9d356ec3febe2b7 to your computer and use it in GitHub Desktop.
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
import pymysql | |
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='my-secret-pw', db='tips', autocommit=True) | |
import pymysql | |
conn = pymysql.connect(host='database-1.c65uwrrkzb8g.us-east-1.rds.amazonaws.com', | |
port=3306, user='admin', passwd='Aa123123', db='aviel', autocommit=True) | |
import pymysql | |
import pymysql | |
conn = pymysql.connect(host='database-1.c65uwrrkzb8g.us-east-1.rds.amazonaws.com', | |
port=3306, user='admin', passwd='Aa123123', db='aviel', autocommit=True) | |
def new_user(): | |
conn = pymysql.connect(host='database-1.c65uwrrkzb8g.us-east-1.rds.amazonaws.com', | |
port=3306, user='admin', passwd='Aa123123', db='aviel', autocommit=True) | |
my_cursor = conn.cursor() | |
username = input("enter new username: ") | |
password = input("enter new password: ") | |
my_cursor.execute(f"insert into users values ('{username}', '{password}')") | |
def get_users(): | |
conn = pymysql.connect(host='database-1.c65uwrrkzb8g.us-east-1.rds.amazonaws.com', | |
port=3306, user='admin', passwd='Aa123123', db='aviel', autocommit=True) | |
my_cursor = conn.cursor() | |
my_cursor.execute("select username from users") | |
for row in my_cursor: | |
print("hello " + row[0]) | |
new_user() | |
new_user() | |
get_users() | |
def input_new_tipper(): | |
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='my-secret-pw', db='tips', autocommit=True) | |
cursor = conn.cursor() | |
id = input("enter user id: ") | |
fname = input("enter user first name: ") | |
lname = input("enter user last name: ") | |
tip_pct = int(input("enter user tip percent: ")) | |
insert_cmd = f"insert into tips_table values ('{id}','{fname}','{lname}', {tip_pct});" | |
cursor.execute(insert_cmd) | |
conn.close() | |
def show_tippers(): | |
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='my-secret-pw', db='tips', autocommit=True) | |
cursor = conn.cursor() | |
cursor.execute("select fname from tips_table") | |
for row in cursor: | |
print(row) | |
conn.close() | |
show_tippers() | |
import requests | |
response = requests.get("https://api.github.com/users/avielb/repos") | |
all_repos = response.json() | |
for i in all_repos: | |
print(i['name']) | |
from flask import Flask, redirect, request | |
app = Flask(__name__) | |
@app.route('/whatismyname', methods=['GET', 'POST', 'DELETE']) | |
def hello(): | |
if request.method == 'GET': | |
return '<font size=7>My name is Aviel</font>' | |
elif request.method == 'POST': | |
return 'creating your name' | |
app.run(host="0.0.0.0", port=5001, debug=True) | |
from flask import Flask, request | |
app = Flask(__name__) | |
@app.route('/whatismyname', methods = ['GET', 'POST', 'DELETE']) | |
def hello(): | |
if request.method == 'GET': | |
return 1/0 | |
elif request.method == 'POST': | |
return 'creating your name' | |
elif request.method == 'DELETE': | |
a = 1/0 | |
return a | |
if __name__ == "__main__": | |
app.run(host="0.0.0.0", port=5002, debug=True) | |
from flask import Flask, redirect, request | |
import pymysql | |
app = Flask(__name__) | |
connection = pymysql.connect(host='database-1.c65uwrrkzb8g.us-east-1.rds.amazonaws.com', port=3306, | |
user='admin', passwd='Aa123123', db='aviel', autocommit=True) | |
def show_animals(cursor_to_execute): | |
cursor_to_execute.execute("select * from animals") | |
result = [] | |
for row in cursor_to_execute: | |
result.append(row[0]) | |
return result | |
@app.route('/whatismyname', methods=['GET', 'POST', 'DELETE']) | |
def hello(): | |
cursor1 = connection.cursor() | |
if request.method == 'GET': | |
return str(show_animals(cursor1)) | |
elif request.method == 'POST': | |
return 'creating your name' | |
app.run(host="0.0.0.0", port=5001, debug=True) | |
------------------ | |
import pymysql | |
from flask import Flask, redirect, request | |
app = Flask(__name__) | |
@app.route('/users', methods=['POST']) | |
def new_user(): | |
conn = pymysql.connect(host='database-1.c65uwrrkzb8g.us-east-1.rds.amazonaws.com', | |
port=3306, user='admin', passwd='Aa123123', db='aviel', autocommit=True) | |
my_cursor = conn.cursor() | |
username = request.form.get("username") | |
password = request.form.get("password") | |
my_cursor.execute(f"insert into users values ('{username}', '{password}')") | |
@app.route('/users', methods=['GET']) | |
def get_users(): | |
conn = pymysql.connect(host='database-1.c65uwrrkzb8g.us-east-1.rds.amazonaws.com', | |
port=3306, user='admin', passwd='Aa123123', db='aviel', autocommit=True) | |
my_cursor = conn.cursor() | |
my_cursor.execute("select username from users") | |
result = [] | |
for row in my_cursor: | |
result.append(row[0]) | |
return str(result) | |
app.run(host="0.0.0.0", port=5001, debug=True) | |
----- | |
import requests | |
requests.post("http://127.0.0.1:5001/users",data={"username": "test2", "password": "bla123"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment