Skip to content

Instantly share code, notes, and snippets.

View dominiksimgen's full-sized avatar

dominiksimgen

View GitHub Profile
# allows python code to be embedded in html
#enables basic arithmetics
<body>
{{3*3}}
</body>
#pass over variables from the python backend to your HTML
# server.py
@app.route('/')
# basic login form
# main.py
from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
class LoginForm(FlaskForm):
# basic 'hello world' server
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World'
#export environment variable via terminal:
# basic SQLite
import sqlite3
db = sqlite3.connect("books-collection.db")
cursor = db.cursor()
cursor.execute("CREATE TABLE books (id INTEGER PRIMARY KEY, title varchar(250) NOT NULL UNIQUE, author varchar(250) NOT NULL, rating FLOAT NOT NULL)")
cursor.execute("INSERT INTO books VALUES(1, 'Harry Potter', 'J. K. Rowling', '9.3')")
db.commit()
@dominiksimgen
dominiksimgen / script.py
Created March 17, 2021 10:05
parse datetime from string
import openpyxl, os, datetime
here = os.path.dirname(os.path.abspath(__file__))
os.chdir(here)
wb = openpyxl.load_workbook("mb51.xlsx")
sheet1 = wb[wb.sheetnames[0]]
date_time_str = sheet1.cell(4,3).value
date_time_obj = datetime.datetime.strptime(date_time_str, '%d.%m.%Y')
print(date_time_obj.isocalendar()[1])
@dominiksimgen
dominiksimgen / read_jason.py
Created February 5, 2021 15:20
how to read and write to JSON files with Python
import json, os
here = os.path.dirname(os.path.abspath(__file__))
os.chdir(here)
f = open("database/locations.json", "r") # open the JSON with read access
data = json.load(f)
f.close()
#do here something with the "data" object like reading and manipulating data
#https://stackoverflow.com/questions/27556751/unprotect-an-excel-file-programmatically
#Windows
def Remove_password_xlsx(filename, pw_str):
xcl = win32com.client.Dispatch("Excel.Application")
wb = xcl.Workbooks.Open(filename, False, False, None, pw_str)
xcl.DisplayAlerts = False
wb.SaveAs(filename, None, '', '')
xcl.Quit()