This new colab notebook comes with: get youtube videos with pytube, converting to audio, show signals, energy and frequency.
You can see this work on the GitHub account.
Is a blog about python programming language. You can see my work with python programming language, tutorials and news.
class TileServer(object):
def __init__(self):
self.imagedict = {}
self.mydict = {}
self.layers = 'ROADMAP'
self.path = './'
self.urlTemplate = 'http://ecn.t{4}.tiles.virtualearth.net/tiles/{3}{5}?g=0'
self.layerdict = {'SATELLITE': 'a', 'HYBRID': 'h', 'ROADMAP': 'r'}
def tiletoquadkey(self, xi, yi, z, layers):
quadKey = ''
for i in range(z, 0, -1):
digit = 0
mask = 1 << (i - 1)
if(xi & mask) != 0:
digit += 1
if(yi & mask) != 0:
digit += 2
quadKey += str(digit)
return quadKey
def loadimage(self, fullname, tilekey):
im = Image.open(fullname)
self.imagedict[tilekey] = im
return self.imagedict[tilekey]
def tile_as_image(self, xi, yi, zoom):
tilekey = (xi, yi, zoom)
result = None
try:
result = self.imagedict[tilekey]
print(result)
except:
print(self.layers)
filename = '{}_{}_{}_{}.jpg'.format(zoom, xi, yi, self.layerdict[self.layers])
print("filename is " + filename)
fullname = self.path + filename
try:
result = self.loadimage(fullname, tilekey)
except:
server = random.choice(range(1,4))
quadkey = self.tiletoquadkey(*tilekey)
print (quadkey)
url = self.urlTemplate.format(xi, yi, zoom, self.layerdict[self.layers], server, quadkey)
print ("Downloading tile %s to local cache." % filename)
urllib.request.urlretrieve(url, fullname)
#urllib.urlretrieve(url, fullname)
result = self.loadimage(fullname, tilekey)
return result
import sys
from PyQt6.QtWidgets import QApplication, QWidget
def main():
app = QApplication(sys.argv)
w = QWidget()
w.resize(250, 200)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()
[root@desk mythcat]# dnf search PyQt6
Last metadata expiration check: 2:03:10 ago on Tue 06 Jul 2021 08:52:41 PM EEST.
No matches found.
[mythcat@desk ~]$ /usr/bin/python3 -m pip install --upgrade pip
...
WARNING: The scripts pip, pip3 and pip3.9 are installed in '/home/mythcat/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning,
use --no-warn-script-location.
Successfully installed pip-21.1.3
[mythcat@desk ~]$ pip install PyQt6 --user
...
import sys
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QApplication, QLabel
def main():
app = QApplication(sys.argv)
win = QLabel()
win.resize(640, 498)
win.setText("Qt is awesome!!!")
win.show()
app.exec()
if __name__ == "__main__":
main()
import os
import io
import sys
import glob
from PIL import Image
from PIL import UnidentifiedImageError
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel
import argparse
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument("files_path", type=Path, help='PATH of folder with files ')
parser.add_argument('-p','--print_files', action='store_true',
help='Print files from folder ')
parser.add_argument('-s','--show', action='store_true',
help='Show image in PyQt5 canvas!')
args = vars(parser.parse_args())
p = parser.parse_args()
print(p.files_path, type(p.files_path), p.files_path.exists())
print(p.show)
files = os.listdir(p.files_path)
file_list = []
image_list = []
bad_files_list =[]
if args['print_files']:
print("These are files from folder "+str(p.files_path))
for f in file_list:
print(f)
images_ext = str(Path(p.files_path))+'/*.png'
print("images_ext: "+images_ext)
for filename in glob.glob(images_ext): #assuming png
try:
f = open(filename, 'rb')
file = io.BytesIO(f.read())
im = Image.open(file)
image_list.append(filename)
print(str(len(image_list))+" good file is"+filename)
except Image.UnidentifiedImageError:
bad_files_list.append(str(p.files_path)+"/"+str(filename))
for f in bad_files_list:
print("bad file is : " + f)
if args['show']:
value = input("Please enter the index of PNG image :\n")
try:
int(value)
print("Image number select default : " + value)
value = int(value)
if value <= len(image_list):
value = int(value)
else:
print("The number image selected is greater then len of list images!")
value = len(image_list)
except:
print("This is not a number, I set first image number.")
value = 1
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.title = "Image Viewer"
self.setWindowTitle(self.title)
label = QLabel(self)
pixmap = QPixmap(image_list[int(value)])
label.setPixmap(pixmap)
self.setCentralWidget(label)
self.resize(pixmap.width(), pixmap.height())
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
[mythcat@desk PIL001]$ python tool001.py
usage: tool001.py [-h] [-p] [-s] files_path
tool001.py: error: the following arguments are required: files_path
[mythcat@desk PIL001]$ python tool001.py ~/Pictures/
/home/mythcat/Pictures True
False
images_ext: /home/mythcat/Pictures/*.png
1 good file is/home/mythcat/Pictures/keyboard.png
2 good file is/home/mythcat/Pictures/Fedora_The_Pirate_CaribbeanHunt.png
3 good file is/home/mythcat/Pictures/website.png
4 good file is/home/mythcat/Pictures/Screenshot from 2021-02-19 19-24-32.png
...
97 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-31-23.png
98 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-46-05.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/Screenshot from 2021-02-07 14-58-56.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/evolution_logo.png
[mythcat@desk PIL001]$ python tool001.py ~/Pictures/ -p
/home/mythcat/Pictures True
False
These are files from folder /home/mythcat/Pictures
images_ext: /home/mythcat/Pictures/*.png
1 good file is/home/mythcat/Pictures/keyboard.png
2 good file is/home/mythcat/Pictures/Fedora_The_Pirate_CaribbeanHunt.png
3 good file is/home/mythcat/Pictures/website.png
...
97 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-31-23.png
98 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-46-05.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/Screenshot from 2021-02-07 14-58-56.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/evolution_logo.png
[mythcat@desk PIL001]$ python tool001.py ~/Pictures/ -s
/home/mythcat/Pictures True
True
images_ext: /home/mythcat/Pictures/*.png
...
97 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-31-23.png
98 good file is/home/mythcat/Pictures/Screenshot from 2021-07-03 17-46-05.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/Screenshot from 2021-02-07 14-58-56.png
bad file is : /home/mythcat/Pictures//home/mythcat/Pictures/evolution_logo.png
Please enter the index of PNG image :
6
Image number select default : 6
[mythcat@desk ~]$ python3.9
Python 3.9.5 (default, May 4 2021, 00:00:00)
[GCC 10.3.1 20210422 (Red Hat 10.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from abc import ABC
>>> class Test_ABC(ABC):
... pass
...
>>> Test_ABC.register(tuple)
>>> assert issubclass(tuple,Test_ABC)
>>> assert isinstance((), Test_ABC)
>>> class Foo:
... def __getitem__(self, index):
... ...
... def __len__(self):
... ...
... def get_iterator(self):
... return iter(self)
...
>>> Test_ABC.register(Foo)
...
from abc import ABC, abstractmethod
class Vehicle(ABC):
@abstractmethod
def action(self):
pass
class Air(Vehicle):
# overriding abstract method
def action(self):
print("this flies in the air")
class Ground(Vehicle):
# overriding abstract method
def action(self):
print("this running on the field")
class Civil(Ground):
def action(self):
print("Civil class - running on the field")
# Can't instantiate abstract class with abstract method action, don't use it
# abc = Vehicle()
abc = Air()
abc.action()
abc = Ground()
abc.action()
abc = Civil()
abc.action()
print( issubclass(Civil, Vehicle))
print( isinstance(Civil(), Vehicle))
[mythcat@desk PythonProjects]$ python3.9 ABC_001.py
this flies in the air
this running on the field
Civil class - running on the field
True
True
import math
print("Round H 2020 - Kick Start 2020: Detect is positive number is called boring.\n")
nr = int(input("get natural positive number: "))
all_cond = []
# detect if the number is odd or even number
def detect_odd_even(num):
if (num % 2) == 0:
#print("{0} is Even number".format(num))
detect = True
else:
#print("{0} is Odd number".format(num))
detect = False
return detect
# check if is an boring number.
def boring_number(num):
for p,num in enumerate(str(num),1):
print(p,num)
if (detect_odd_even(p) == detect_odd_even(int(num))): all_cond.append(True)
else:
all_cond.append(False)
# check the number is
boring_number(nr)
# print result if the positive number is boring
if (all(all_cond) == True): print("{0} is an positive boring number".format(nr))
else:
print("{0} is not a positive boring number".format(nr))
~/mathissues$ python math_003.py
Round H 2020 - Kick Start 2020: Detect is positive number is called boring.
get natural positive number: 345
(1, '3')
(2, '4')
(3, '5')
345 is an positive boring number
import math
print("Round H 2020 - Kick Start 2020: Detect is positive number is called boring.\n")
#nr = int(input("get natural positive number: "))
all_cond = []
# detect if the number is odd or even number
def detect_odd_even(num):
if (num % 2) == 0:
#print("{0} is Even number".format(num))
detect = True
else:
#print("{0} is Odd number".format(num))
detect = False
return detect
# check if is an boring number.
def boring_number(num):
for p,num in enumerate(str(num),1):
print(p,num)
if (detect_odd_even(p) == detect_odd_even(int(num))): all_cond.append(True)
else:
all_cond.append(False)
# check the number is
#boring_number(nr)
# print result if the positive number is boring
nr1 = int(input("get firt natural positive number: "))
nr2 = int(input("get firt natural positive number: "))
if nr1 < nr2:
n1 = nr1
n2 = nr2
else:
n1 = nr2
n2 = nr1
for all_nr in range(n1,n2):
all_cond = []
boring_number(all_nr)
print(all_nr)
# print result if the positive number is boring
if (all(all_cond) == True): print("{0} is an positive boring number".format(all_nr))
else: print("{0} is not a positive boring number".format(all_nr))
all_cond = []
~/mathissues$ python math_003.py
Round H 2020 - Kick Start 2020: Detect is positive number is called boring.
get firt natural positive number: 11
get firt natural positive number: 16
(1, '1')
(2, '1')
11
11 is not a positive boring number
(1, '1')
(2, '2')
12
12 is an positive boring number
(1, '1')
(2, '3')
13
13 is not a positive boring number
(1, '1')
(2, '4')
14
14 is an positive boring number
(1, '1')
(2, '5')
15
15 is not a positive boring number
import requests
id = input("Type id sattelite: ")
satellite_id = id
url = 'https://api.spectator.earth/satellite/{satellite_id}'.format(satellite_id=satellite_id)
response = requests.get(url)
data = response.json()
print(data)
[mythcat@desk Spectator]$ python satellite_all.py
Type id sattelite: 1
{'id': 1, 'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-51.88851761326367,
70.75978200389422]}, 'properties': {'name': 'Sentinel-1A', 'norad_id': 39634, 'sensors':
[{'type': 'SAR', 'avg_footprint_width': '3.20'}], 'open': True, 'platform': 'Sentinel-1A'}}
[mythcat@desk Spectator]$ python satellite_all.py
Type id sattelite: 2
{'id': 2, 'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [42.046601163641796,
-14.660442921557335]}, 'properties': {'name': 'Sentinel-2A', 'norad_id': 40697, 'sensors':
[{'type': 'OPTICAL', 'avg_footprint_width': '2.32'}], 'open': True, 'platform': 'Sentinel-2A'}}
[mythcat@desk Spectator]$ python satellite_all.py
Type id sattelite: 3
{'id': 3, 'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-91.98478583784988,
79.45732380441011]}, 'properties': {'name': 'Sentinel-3A', 'norad_id': 41335, 'sensors':
[{'type': 'OPTICAL', 'avg_footprint_width': '10.16'}, {'type': 'OPTICAL',
'avg_footprint_width': '11.20'}], 'open': True, 'platform': 'Sentinel-3A'}}
[mythcat@desk Spectator]$ python satellite_all.py
Type id sattelite: 4
Let's see one example with satellite overpasses:
import requests
import json
api_key = input("api_key :")
bbox = '19.59,49.90,20.33,50.21'
satellites = 'Sentinel-2A,Sentinel-2B'
url = 'https://api.spectator.earth/overpass/?api_key={api_key}&bbox={bbox}&
satellites={satellites}'.format(api_key=api_key, bbox=bbox, satellites=satellites)
response = requests.get(url)
data = response.json()
print(type(data))
print(data)
[mythcat@desk Spectator]$ python satellite.py
api_key :....
...
{'frequency': 93996, 'overpasses': [{'id': 16486437, 'acquisition': True, 'date':
'2021-02-26T09:57:00Z', 'footprint': {'type': 'Polygon', 'coordinates':
...
footprint': {'type': 'Polygon', 'coordinates':
...
[[[19.153675312697636, 46.847554078717884], ...