This file contains hidden or 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
SQLITE DATE - TIME - DATETIME YOUTUBE TUT | |
https://www.youtube.com/watch?v=nJRvz5Rhrx0 | |
# Insert DEFAULT timestamp "now" as INTEGER | |
# and unixepoch prior SQLITE 3.38 (2022-02-22). | |
#################################################### | |
create table t1 (c1 TEXT, c2 INTEGER DEFAULT (strftime('%s', 'now'))); | |
insert into t1(c1) values ('drink'),('eat'); |
This file contains hidden or 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
""" | |
The walrus operator “:=” is an operator used to evaluate, assign, and return value from a single statement in Python. | |
It was introduced in Python 3.8 | |
""" | |
sss = {'color': 'red', 'size': 'l', 'clips': {'number': 6, 'material': 'metal'}} | |
if value := sss.get("clips", {}).get("number"): | |
print(f"Number of clips: {value}") | |
""" |
This file contains hidden or 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 json | |
my_favorite = {"product": "Stella", "flavors": ["walnut", "prune"], "ranking": None, "price": 1.15, "in_stock": False } | |
""" | |
json.dumps() function converts a subset of Python objects into a json string. | |
""" | |
my_favorite_json = json.dumps(my_favorite , indent=2, sort_keys=True) | |
print(my_favorite_json) |
This file contains hidden or 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
# app.py | |
# https://stackoverflow.com/questions/74213961/how-create-endpoints-in-multiple-files | |
# https://flask.palletsprojects.com/en/stable/blueprints/ | |
from flask import Flask, jsonify, request | |
from candy import candy_bp | |
from beer import beer_bp | |
from netz import netz_bp |
This file contains hidden or 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
from typing import NamedTuple | |
class PJ (NamedTuple): | |
make: str | |
model: str | |
color: str | |
straps: int | |
price: float | |
stars: int |
This file contains hidden or 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
# try to sort ipv4 addr as strings | |
ss = ['114.122.102.2','114.122.11.1','118.123.12.13','122.14.113.3','192.144.1.5'] | |
print([str(s) for s in sorted(ss)]) | |
# this does not look righ to me ... let's invoke the ipaddress module | |
from ipaddress import IPv4Address | |
# and create the ipv4 addr instances | |
sso = [IPv4Address(s) for s in ss] | |
#print the sorted ipv4 addr | |
print([str(s) for s in sorted(sso)]) |
This file contains hidden or 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 datetime | |
d1_date_str='29/08/1962' | |
d2_date_str= '06/06/1968' | |
d1_date_obj=datetime.datetime.strptime(d1_date_str, '%d/%m/%Y') | |
print(d1_date_obj.date()) | |
d2_date_obj=datetime.datetime.strptime(d2_date_str, '%d/%m/%Y') | |
print(d2_date_obj.date()) | |
#create datetime.timedelta object | |
diff = d2_date_obj - d1_date_obj | |
print(type(diff)) |
This file contains hidden or 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 zipfile | |
from datetime import datetime | |
# create zip file name | |
zip_file_name = 'myzip_{}.zip'.format(datetime.now().strftime("%d%m%Y")) | |
# create a ZipFile object and compress | |
zipObj = zipfile.ZipFile(zip_file_name, 'w', zipfile.ZIP_DEFLATED) | |
# Add multiple files to the zip |
This file contains hidden or 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
from collections import Counter | |
file_list=!find /home/bruno/tbc/uwsgi/ -type f -name "*" | |
#print(file_list) | |
found_ext=[] | |
for f in file_list: | |
found_ext.append(f.split('/')[-1].split('.')[-1]) | |
#print(found_ext) | |
print(Counter(found_ext)) |
This file contains hidden or 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 requests | |
import urllib3 | |
import json | |
# Surpress SSL/TLS >Insecure Warnings | |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
session = requests.Session() | |
session.auth = ('admin', 'infoblox') |
NewerOlder