Skip to content

Instantly share code, notes, and snippets.

View sd2001's full-sized avatar
🎯
Focusing

Swarnabha Das sd2001

🎯
Focusing
View GitHub Profile
## row_count = 10
## offset = 2
SELECT
column_list
FROM
table1
ORDER BY column_list
LIMIT row_count OFFSET offset;
@sd2001
sd2001 / boto.py
Created November 4, 2022 08:16
Upload photos from python backend to s3
"""
An example flask application showing how to upload a file to S3
while creating a REST API using Flask-Restful.
Note: This method of uploading files is fine for smaller file sizes,
but uploads should be queued using something like celery for
larger ones.
"""
from cStringIO import StringIO
from boto.s3.connection import S3Connection
@sd2001
sd2001 / gunicorn conf
Created November 4, 2022 08:09
Configuring gunicorn workers from backend
```from flask_script import Command, Option
class GunicornServer(Command):
description = 'Run the app within Gunicorn'
def __init__(self, host='127.0.0.1', port=8000, workers=4):
self.port = port
self.host = host
self.workers = workers
@sd2001
sd2001 / flask_mail.py
Created November 4, 2022 08:05
How to configure flask app to send email
from flask_mail import Mail, Message
from flask import Flask
app = Flask(__name__)
app.config.update(
DEBUG=True,
#EMAIL SETTINGS
MAIL_SERVER='smtp.gmail.com',
MAIL_PORT=465,
MAIL_USE_SSL=True,
MAIL_USERNAME = 'your email',
@sd2001
sd2001 / sqlalchemy.py
Last active November 4, 2022 07:53
SQLalchemy create a table after connecting to database
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Table, ForeignKey
from sqlalchemy.types import Integer, String, DateTime
from sqlalchemy.orm import relationship, backref, session
app = Flask(__name__)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///user.db'
# pip insstall bcrypt
import bcrypt
from getpass import getpass
#Retrieve the password and encrypt
master_secret_key = getpass()
salt = bcrypt.gensalt()
pw = bcrypt.hashpw(master_secret_key.encode(), salt)
#username and password must to be stored somewhere potentially a keyring API?
def weather_detail(place,unit,hr,m):
mgr=owm.weather_manager()
forecaster = mgr.forecast_at_place(place, '3h')
time=timestamps.tomorrow(hr,m)
weather=forecaster.get_weather_at(time)
t=weather.temperature(unit)['temp']
st.write(f"## Temperature at {place} for the selected time in {unit} is {t}")
st.title(f"Expected Temperature Changes/Alerts at {hr}:{m}")
def plot_line(days,min_t,max_t):
days=dates.date2num(days)
rcParams['figure.figsize']=6,4
plt.plot(days,max_t,color='green',linestyle='dashdot',linewidth = 1,marker='o',markerfacecolor='red',markersize=7)
plt.plot(days,min_t,color='orange',linestyle='dashdot',linewidth = 1,marker='o',markerfacecolor='blue',markersize=7)
plt.ylim(min(min_t)-4,max(max_t)+4)
plt.xticks(days)
x_y_axis=plt.gca()
xaxis_format=dates.DateFormatter('%m/%d')
st.title("TOMORROW'S WEATHER FORECAST")
place1=st.text_input("NAME OF THE CITY FOR TOMORROW'S FORECAST:", "")
unit1=st.selectbox("Select Temperature Unit for tomorrow's forecast",("celsius","fahrenheit"))
hr1=st.slider("Hour :",min_value=0,max_value=23,step=1)
m1=st.slider("Minute :",min_value=0,max_value=59,step=5)
c=st.button("SUBMIT INFO ")
st.title("Weather Forecast")
st.write("## Made by Swarnabha with ❤️")
st.write("### Write the name of a City and select the Temperature Unit and Graph Type :")
place=st.text_input("NAME OF THE CITY :", "")
unit=st.selectbox("Select Temperature Unit",("Celsius","Fahrenheit"))
g_type=st.selectbox("Select Graph Type",("Line Graph","Bar Graph"))
b=st.button("SUBMIT")