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
from typing import NamedTuple | |
class PJ (NamedTuple): | |
make: str | |
model: str | |
color: str | |
straps: int | |
price: float | |
stars: int |
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
# 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 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 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 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 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') |
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
https://hub.docker.com/r/d3fk/python_in_bottle/ | |
docker pull d3fk/python_in_bottle | |
docker run -itd --name nra_site_inventory --rm -p 8080:8080 -v $(pwd)/yEd-SiteInventory:/usr/src/myapp -w /usr/src/myapp d3fk/python_in_bottle:latest python site_inventory.py | |
# This prevents Python from writing out pyc files | |
docker run -itd --name nra_site_inventory --rm -e PYTHONDONTWRITEBYTECODE="1" -p 8080:8080 -v $(pwd)/yEd-SiteInventory:/usr/src/myapp -w /usr/src/myapp d3fk/python_in_bottle:latest python site_inventory.py | |
docker stop nra_site_inventory |
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
***************************************************** | |
*** APPROACH 1: install uwsgi as a system package *** | |
***************************************************** | |
install packages | |
---------------- | |
apt install uwsgi uwsgi-plugin-python3 | |
Configure uwsgi daemon | |
---------------------- |
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
find . -type f -name "*.py[co]" -delete -or -type d -name "__pycache__" -delete |
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
''' | |
Ref: https://community.infoblox.com/t5/DNS-DHCP-IPAM/WAPI-Web-API-Sample-Code-for-NIOS/m-p/105/highlight/true#M12 | |
Sample -- sample python application for WAPI | |
''' | |
import sys | |
import json |
NewerOlder