misc python code
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.pyc
|
||||||
|
*.db
|
||||||
1
code/misc/python/scripts/AI/.python-version
Normal file
1
code/misc/python/scripts/AI/.python-version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3.9
|
||||||
0
code/misc/python/scripts/AI/embeddings.ipynb
Normal file
0
code/misc/python/scripts/AI/embeddings.ipynb
Normal file
132
code/misc/python/scripts/ANKI Card templates.ipynb
Normal file
132
code/misc/python/scripts/ANKI Card templates.ipynb
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 27,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Latex Anki Card - Bulk Division"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 19,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"def Form1(dividend,divisor):\n",
|
||||||
|
" tmp=\"\"\"Solve [latex]\\mydiv {{{div}}}{{{divid}}} [/latex]\"\"\".format(div=divisor,divid=dividend)\n",
|
||||||
|
" return tmp\n",
|
||||||
|
"\n",
|
||||||
|
"def Form2(dividend,divisor):\n",
|
||||||
|
" tmp=\"\"\"Solve [$] {{{divid}}} \\div {{{div}}} [/$]\"\"\".format(div=divisor,divid=dividend)\n",
|
||||||
|
" return tmp\n",
|
||||||
|
"\n",
|
||||||
|
"def Form3(dividend,divisor):\n",
|
||||||
|
" tmp=\"\"\"Solve [$] \\\\frac {{{divid}}}{{{div}}} [/$]\"\"\".format(div=divisor,divid=dividend)\n",
|
||||||
|
" return tmp\n",
|
||||||
|
"\n",
|
||||||
|
"def Back(dividend,divisor):\n",
|
||||||
|
" ans=dividend/divisor\n",
|
||||||
|
" rounded1=round(ans,1)\n",
|
||||||
|
" rounded2=round(ans,2)\n",
|
||||||
|
" rounded3=round(ans,3)\n",
|
||||||
|
" temp=\"\"\" Answer(3 D.P):\\n\n",
|
||||||
|
" {ans3} \\n\\n\n",
|
||||||
|
" Working:\\n\n",
|
||||||
|
" [$]\\longdivision[stage=5] {{{divid}}}{{{div}}}[/$]\n",
|
||||||
|
"\n",
|
||||||
|
" Check Answer:\\n\n",
|
||||||
|
" [$]\\opmul{{{ans3}}}{{{div}}} \\quad \\opmul{{{ans2}}}{{{div}}} \n",
|
||||||
|
" [/$]\\n \"\"\".format(ans2=rounded2, ans3=rounded3, divid=dividend, div=divisor)\n",
|
||||||
|
" return temp\n",
|
||||||
|
"\n",
|
||||||
|
"dividends=[1023, 300, 300,300, 3520, 3932.5, 4732, 532.5,532.5,532.5,423, 4750]\n",
|
||||||
|
"divisor=[9, 2000, 2475, 400, 10, 45,9,10,15,60,3,8]\n",
|
||||||
|
"\n",
|
||||||
|
"lsf1=[]\n",
|
||||||
|
"lsf2=[]\n",
|
||||||
|
"lsf3=[]\n",
|
||||||
|
"lsb=[]\n",
|
||||||
|
"lst=[]\n",
|
||||||
|
"for divid, div in zip(dividends,divisor):\n",
|
||||||
|
" lsf1.append (Form1(divid,div))\n",
|
||||||
|
" lsf2.append (Form2(divid,div))\n",
|
||||||
|
" lsf3.append (Form3(divid,div))\n",
|
||||||
|
" lsb.append (Back(divid,div))\n",
|
||||||
|
" lst.append ('Division')\n",
|
||||||
|
"\n",
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 20,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from pathlib import Path\n",
|
||||||
|
"location=Path('/home/dl92/SynologyDrive/Kids/Miri/FlashCards')\n",
|
||||||
|
"fname=location / 'Division.csv'\n",
|
||||||
|
"pd.DataFrame({'Form1':lsf1,'Form2':lsf2,'Form3':lsf3,'Back':lsb,'Tag':lst}).to_csv(fname,header=False, index=False)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3.6.9 64-bit",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python36964bit5aad4b8392a24ab49b91cfc5ab558ab3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.6.9"
|
||||||
|
},
|
||||||
|
"toc": {
|
||||||
|
"base_numbering": 1,
|
||||||
|
"nav_menu": {},
|
||||||
|
"number_sections": true,
|
||||||
|
"sideBar": true,
|
||||||
|
"skip_h1_title": false,
|
||||||
|
"title_cell": "Table of Contents",
|
||||||
|
"title_sidebar": "Contents",
|
||||||
|
"toc_cell": false,
|
||||||
|
"toc_position": {},
|
||||||
|
"toc_section_display": true,
|
||||||
|
"toc_window_display": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
|
}
|
||||||
212
code/misc/python/scripts/Anki/workflow.ipynb
Normal file
212
code/misc/python/scripts/Anki/workflow.ipynb
Normal file
File diff suppressed because one or more lines are too long
21
code/misc/python/scripts/ComputableDocs/_quarto.yml
Normal file
21
code/misc/python/scripts/ComputableDocs/_quarto.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
project:
|
||||||
|
type: website
|
||||||
|
|
||||||
|
website:
|
||||||
|
title: "ComputableDocs"
|
||||||
|
navbar:
|
||||||
|
left:
|
||||||
|
- href: index.qmd
|
||||||
|
text: Home
|
||||||
|
- href: musicdownload.qmd
|
||||||
|
text: Music Download
|
||||||
|
- about.qmd
|
||||||
|
|
||||||
|
format:
|
||||||
|
html:
|
||||||
|
theme: cosmo
|
||||||
|
css: styles.css
|
||||||
|
toc: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
5
code/misc/python/scripts/ComputableDocs/about.qmd
Normal file
5
code/misc/python/scripts/ComputableDocs/about.qmd
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
title: "About"
|
||||||
|
---
|
||||||
|
|
||||||
|
About this site
|
||||||
560
code/misc/python/scripts/ComputableDocs/audioconversion.ipynb
Normal file
560
code/misc/python/scripts/ComputableDocs/audioconversion.ipynb
Normal file
File diff suppressed because one or more lines are too long
7
code/misc/python/scripts/ComputableDocs/index.qmd
Normal file
7
code/misc/python/scripts/ComputableDocs/index.qmd
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
title: "ComputableDocs"
|
||||||
|
---
|
||||||
|
|
||||||
|
This is a Quarto website.
|
||||||
|
|
||||||
|
To learn more about Quarto websites visit <https://quarto.org/docs/websites>.
|
||||||
276
code/misc/python/scripts/ComputableDocs/musicdownload.qmd
Normal file
276
code/misc/python/scripts/ComputableDocs/musicdownload.qmd
Normal file
@@ -0,0 +1,276 @@
|
|||||||
|
---
|
||||||
|
title: "DownloadPage"
|
||||||
|
code-fold: true
|
||||||
|
execute:
|
||||||
|
enabled: true
|
||||||
|
cache: false
|
||||||
|
jupyter: python3
|
||||||
|
format:
|
||||||
|
html:
|
||||||
|
toc: true
|
||||||
|
code-fold: true
|
||||||
|
html-math-method: katex
|
||||||
|
css: styles.css
|
||||||
|
---
|
||||||
|
|
||||||
|
# Miri's requests!
|
||||||
|
|
||||||
|
```{python}
|
||||||
|
#| echo: true
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from pytube import YouTube
|
||||||
|
from pytube import Playlist
|
||||||
|
import moviepy.editor as mp
|
||||||
|
from youtube_transcript_api import YouTubeTranscriptApi
|
||||||
|
from pathvalidate import sanitize_filepath
|
||||||
|
|
||||||
|
def convert_mp4_to_mp3(file,oppath):
|
||||||
|
try:
|
||||||
|
# Load the video file
|
||||||
|
#video = mp.VideoFileClip(file)
|
||||||
|
audio=mp.AudioFileClip(str(file))
|
||||||
|
stem=str(file.stem)#.replace.rstrip().lstrip()
|
||||||
|
|
||||||
|
oppath=oppath/'mp3'
|
||||||
|
oppath.mkdir(parents=True,exist_ok=True)
|
||||||
|
audio_path=sanitize_filepath(oppath/f'{stem}.mp3')
|
||||||
|
print('audio_path', stem, audio_path)
|
||||||
|
|
||||||
|
# Extract the audio from the video and save it as an MP3 file
|
||||||
|
#video.audio.write_audiofile(audio_path, codec='pcm_s16le')
|
||||||
|
audio.write_audiofile(str(audio_path),write_logfile=True,verbose=True)#, codec='pcm_s16le')
|
||||||
|
|
||||||
|
# Print a success message
|
||||||
|
print(f"Audio extracted and saved as: {audio_path}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error converting MP4 to MP3: {e}")
|
||||||
|
|
||||||
|
def convert_mp4_to_wav(file,oppath):
|
||||||
|
try:
|
||||||
|
# Load the video file
|
||||||
|
#video = mp.VideoFileClip(file)
|
||||||
|
audio=mp.AudioFileClip(str(file))
|
||||||
|
stem=str(file.stem)#.replace.rstrip().lstrip()
|
||||||
|
oppath=oppath/'wav'
|
||||||
|
oppath.mkdir(parents=True,exist_ok=True)
|
||||||
|
|
||||||
|
audio_path=sanitize_filepath(oppath/f'{stem}.wav')
|
||||||
|
print('audio_path', stem, audio_path)
|
||||||
|
# Extract the audio from the video and save it as an MP3 file
|
||||||
|
#video.audio.write_audiofile(audio_path, codec='pcm_s16le')
|
||||||
|
audio.write_audiofile(str(audio_path),codec='pcm_s16le',write_logfile=False,verbose=True)#, codec='pcm_s16le')
|
||||||
|
|
||||||
|
# Print a success message
|
||||||
|
print(f"Audio extracted and saved as: {audio_path}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error converting MP4 to MP3: {e}")
|
||||||
|
|
||||||
|
def download_mp4(video_url,oppath):
|
||||||
|
# Get the YouTube object
|
||||||
|
yt = YouTube(video_url)
|
||||||
|
|
||||||
|
# Get video title and language
|
||||||
|
title = yt.title
|
||||||
|
# print (title)
|
||||||
|
|
||||||
|
video_stream = yt.streams.filter(adaptive=True).order_by('abr')
|
||||||
|
# print(video_stream)
|
||||||
|
fname=sanitize_filepath(oppath/ f'{title}.mp4')
|
||||||
|
video_stream.last().download(filename=oppath/ f'{title}.mp4')
|
||||||
|
return fname
|
||||||
|
|
||||||
|
def download_songlist(songs,oppath):
|
||||||
|
|
||||||
|
for song in songs:
|
||||||
|
try:
|
||||||
|
file=download_mp4(song,oppath)
|
||||||
|
convert_mp4_to_mp3(file,oppath)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error downloading file: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
def download_playlist(url_playlist,oppath):
|
||||||
|
playlist = Playlist(url_playlist)
|
||||||
|
ls=[]
|
||||||
|
for urls in playlist.video_urls:
|
||||||
|
ls.append(urls)
|
||||||
|
|
||||||
|
download_songlist(ls,oppath)
|
||||||
|
return
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
fix pytube issue
|
||||||
|
|
||||||
|
```{python}
|
||||||
|
|
||||||
|
from pytube import cipher
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def get_throttling_function_name(js: str) -> str:
|
||||||
|
"""Extract the name of the function that computes the throttling parameter.
|
||||||
|
|
||||||
|
:param str js:
|
||||||
|
The contents of the base.js asset file.
|
||||||
|
:rtype: str
|
||||||
|
:returns:
|
||||||
|
The name of the function used to compute the throttling parameter.
|
||||||
|
"""
|
||||||
|
function_patterns = [
|
||||||
|
# https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
|
||||||
|
# https://github.com/yt-dlp/yt-dlp/commit/48416bc4a8f1d5ff07d5977659cb8ece7640dcd8
|
||||||
|
# var Bpa = [iha];
|
||||||
|
# ...
|
||||||
|
# a.C && (b = a.get("n")) && (b = Bpa[0](b), a.set("n", b),
|
||||||
|
# Bpa.length || iha("")) }};
|
||||||
|
# In the above case, `iha` is the relevant function name
|
||||||
|
r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*'
|
||||||
|
r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)',
|
||||||
|
r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])\([a-z]\)',
|
||||||
|
]
|
||||||
|
logger.debug('Finding throttling function name')
|
||||||
|
for pattern in function_patterns:
|
||||||
|
regex = re.compile(pattern)
|
||||||
|
function_match = regex.search(js)
|
||||||
|
if function_match:
|
||||||
|
logger.debug("finished regex search, matched: %s", pattern)
|
||||||
|
if len(function_match.groups()) == 1:
|
||||||
|
return function_match.group(1)
|
||||||
|
idx = function_match.group(2)
|
||||||
|
if idx:
|
||||||
|
idx = idx.strip("[]")
|
||||||
|
array = re.search(
|
||||||
|
r'var {nfunc}\s*=\s*(\[.+?\]);'.format(
|
||||||
|
nfunc=re.escape(function_match.group(1))),
|
||||||
|
js
|
||||||
|
)
|
||||||
|
if array:
|
||||||
|
array = array.group(1).strip("[]").split(",")
|
||||||
|
array = [x.strip() for x in array]
|
||||||
|
return array[int(idx)]
|
||||||
|
|
||||||
|
raise RegexMatchError(
|
||||||
|
caller="get_throttling_function_name", pattern="multiple"
|
||||||
|
)
|
||||||
|
|
||||||
|
cipher.get_throttling_function_name = get_throttling_function_name
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## song list 2024-06-24
|
||||||
|
|
||||||
|
- [Sabrina Carpenter - Please Please Please (Lyric Video)](https://www.youtube.com/watch?v=Yl_thbk40A0)
|
||||||
|
- [Sabrina Carpenter - Espresso (Lyrics)](https://www.youtube.com/watch?v=kVC3BSBm2Dc)
|
||||||
|
- [Kaash Paige - Love Songs (Lyrics)](https://www.youtube.com/watch?v=7P4q7Oo67-U)
|
||||||
|
- [L’AMOUR DE MA VIE (Lyrics)](https://www.youtube.com/watch?v=RhGaivzNHps)
|
||||||
|
- [SZA Greatest Hits Full Album 2024](https://www.youtube.com/watch?v=W6kc4k4NmWQ)
|
||||||
|
- [Eminem - Just Lose It (Official Music Video)](https://www.youtube.com/watch?v=9dcVOmEQzKA)
|
||||||
|
- [Rihanna New Playlist 2023](https://www.youtube.com/watch?v=5o9AQs4GOeA)
|
||||||
|
- [Eminem - Houdini (Perfectly Clean)](https://www.youtube.com/watch?v=YMwWZXQ9xQU)
|
||||||
|
- [Tyla - Water (Lyrics)](https://www.youtube.com/watch?v=A81ZfezsLcM)
|
||||||
|
|
||||||
|
```{python}
|
||||||
|
p=!pwd
|
||||||
|
#p[0]
|
||||||
|
#!tree {p[0]}
|
||||||
|
|
||||||
|
musicpath='~/Music/Miri'
|
||||||
|
!tree -d {musicpath}
|
||||||
|
```
|
||||||
|
|
||||||
|
```{python}
|
||||||
|
|
||||||
|
#| echo: false
|
||||||
|
#| output: false
|
||||||
|
#| eval: false
|
||||||
|
|
||||||
|
oppath=Path('/home/ys/Music/Miri/7_playlist')
|
||||||
|
|
||||||
|
list_20240624=['https://www.youtube.com/watch?v=Yl_thbk40A0',
|
||||||
|
'https://www.youtube.com/watch?v=kVC3BSBm2Dc',
|
||||||
|
'https://www.youtube.com/watch?v=7P4q7Oo67-U',
|
||||||
|
'https://www.youtube.com/watch?v=RhGaivzNHps',
|
||||||
|
'https://www.youtube.com/watch?v=W6kc4k4NmWQ',
|
||||||
|
'https://www.youtube.com/watch?v=9dcVOmEQzKA',
|
||||||
|
'https://www.youtube.com/watch?v=5o9AQs4GOeA',
|
||||||
|
'https://www.youtube.com/watch?v=YMwWZXQ9xQU',
|
||||||
|
'https://www.youtube.com/watch?v=A81ZfezsLcM']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
list_20240624
|
||||||
|
download_songlist(list_20240624,oppath)
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## song list 2024-10-05
|
||||||
|
|
||||||
|
- [sza playlist 1](https://youtu.be/455TWGwAObA?si=GZVF3c86L57d8MsF)
|
||||||
|
- [sza playlist 2](https://youtu.be/IlnxfwtCqLU?si=TjdWp9QbSG2LM2E9) #did not download
|
||||||
|
- [travis scott clean](https://youtu.be/7tcYOY50yXg?si=2zYcfSbta9WhTzGd)
|
||||||
|
- [rihanna playlist](https://youtu.be/5o9AQs4GOeA?si=I0YLFJQl0YwEx9AG) #did not download
|
||||||
|
- [weekend playlist](https://youtu.be/mPXBHFFUgzw?si=g4fhhhza2COvSnLZ) #did not download
|
||||||
|
- [travis scott clean 2](https://youtu.be/JPo3xwzupbE?si=B32de3hrHuaG283K)
|
||||||
|
- [power is power clean](https://youtu.be/iFwQcBoljoo?si=cXrK5-RDq77rvWmh)
|
||||||
|
|
||||||
|
```{python}
|
||||||
|
|
||||||
|
#| echo: false
|
||||||
|
#| output: false
|
||||||
|
#| eval: true
|
||||||
|
|
||||||
|
oppath=Path('/home/ys/Music/Miri/8_playlist')
|
||||||
|
oppath.mkdir(parents=True,exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
list_20241005=['https://youtu.be/455TWGwAObA?si=GZVF3c86L57d8MsF',
|
||||||
|
'https://youtu.be/IlnxfwtCqLU?si=TjdWp9QbSG2LM2E9',
|
||||||
|
'https://youtu.be/7tcYOY50yXg?si=2zYcfSbta9WhTzGd',
|
||||||
|
'https://youtu.be/5o9AQs4GOeA?si=I0YLFJQl0YwEx9AG)',
|
||||||
|
'https://youtu.be/mPXBHFFUgzw?si=g4fhhhza2COvSnLZ',
|
||||||
|
'https://youtu.be/JPo3xwzupbE?si=B32de3hrHuaG283K',
|
||||||
|
'https://youtu.be/iFwQcBoljoo?si=cXrK5-RDq77rvWmh'
|
||||||
|
]
|
||||||
|
|
||||||
|
download_songlist(list_20241005,oppath)
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
# My downloads
|
||||||
|
## song list 2024-07-13
|
||||||
|
|
||||||
|
- [Vicente Amigo - De Mi Corazón Al Aire](https://www.youtube.com/watch?v=6RZwLta9MHg&list=OLAK5uy_lHANtM_kWgkJVkbl8w83LuIyL8QIIBMWE&index=1)
|
||||||
|
|
||||||
|
- [Vicente Amigo - Vivencias Imaginadas](https://www.youtube.com/watch?v=cvrg4wn7vlQ&list=OLAK5uy_nl4MMy9w40xh1g4KPGbZfB7bs9_ga6Mho&index=2)
|
||||||
|
|
||||||
|
- [Vicente Amigo - Ciudad De Las Ideas](https://www.youtube.com/watch?v=QyBNAtr44X8&list=PLlf0nWXS9c9CRKpqe08BVKtzO7FHXW6sF)
|
||||||
|
|
||||||
|
```{python}
|
||||||
|
|
||||||
|
#| echo: false
|
||||||
|
#| output: false
|
||||||
|
#| eval: false
|
||||||
|
|
||||||
|
oppath=Path('/home/ys/Music/youtube')/'Vicente Amigo'/'De Mi Corazon Al Aire'
|
||||||
|
oppath.mkdir(parents=True,exist_ok=True)
|
||||||
|
#download_playlist('https://www.youtube.com/watch?v=6RZwLta9MHg&list=OLAK5uy_lHANtM_kWgkJVkbl8w83LuIyL8QIIBMWE&index=1',oppath)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
oppath=Path('/home/ys/Music/youtube')/'Vicente Amigo'/'Vivencias Imaginadas'
|
||||||
|
oppath.mkdir(parents=True,exist_ok=True)
|
||||||
|
#download_playlist('https://www.youtube.com/watch?v=cvrg4wn7vlQ&list=OLAK5uy_nl4MMy9w40xh1g4KPGbZfB7bs9_ga6Mho&index=1',oppath)
|
||||||
|
|
||||||
|
oppath=Path('/home/ys/Music/youtube')/'Vicente Amigo'/'Ciudad De Las Ideas'
|
||||||
|
oppath.mkdir(parents=True,exist_ok=True)
|
||||||
|
#download_playlist('https://www.youtube.com/watch?v=QyBNAtr44X8&list=PLlf0nWXS9c9CRKpqe08BVKtzO7FHXW6sF',oppath)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
1
code/misc/python/scripts/ComputableDocs/styles.css
Normal file
1
code/misc/python/scripts/ComputableDocs/styles.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/* css styles */
|
||||||
0
code/misc/python/scripts/DOTNETtesting.ipynb
Normal file
0
code/misc/python/scripts/DOTNETtesting.ipynb
Normal file
331
code/misc/python/scripts/DigitalPaper Management.ipynb
Normal file
331
code/misc/python/scripts/DigitalPaper Management.ipynb
Normal file
@@ -0,0 +1,331 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import json\n",
|
||||||
|
"import os\n",
|
||||||
|
"\n",
|
||||||
|
"from dptrp1.dptrp1 import DigitalPaper\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import getpass\n",
|
||||||
|
"import os\n",
|
||||||
|
"\n",
|
||||||
|
"password = getpass.getpass()\n",
|
||||||
|
"command = \"sudo -S sudo chmod 666 /dev/ttyACM0\" #can be any command but don't forget -S as it enables input from stdin\n",
|
||||||
|
"os.system('echo %s | %s' % (password, command))\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 8,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"/dev/ttyACM0\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import serial\n",
|
||||||
|
"ser = serial.Serial('/dev/ttyACM0') # open serial port\n",
|
||||||
|
"print(ser.name) # check which port was really used\n",
|
||||||
|
"ser.write(b'\\x01\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x00\\x04') # write a string b\"\\x01\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x00\\x04\"\n",
|
||||||
|
"ser.close() # close port\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"client_id=''\n",
|
||||||
|
"key=''\n",
|
||||||
|
"SYNC_DIR = '/home/dl92/Downloads/DigitalPaper/'\n",
|
||||||
|
"def connect(address=''):\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" Loads the key and client ID to authenticate with the DPT-RP1\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" with open('/home/dl92/.dpt-client.txt', 'r') as f:\n",
|
||||||
|
" client_id = f.readline().strip()\n",
|
||||||
|
"\n",
|
||||||
|
" with open('/home/dl92/.dpt-key.txt', 'r') as f:\n",
|
||||||
|
" key = f.read()\n",
|
||||||
|
"\n",
|
||||||
|
" dpt = DigitalPaper(address)\n",
|
||||||
|
" dpt.authenticate(client_id, key)\n",
|
||||||
|
" return dpt\n",
|
||||||
|
"\n",
|
||||||
|
"def sync(dpt):\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" Given an authenticated DigitalPaper instance, download all note files to a\n",
|
||||||
|
" specified directory.\n",
|
||||||
|
" \"\"\"\n",
|
||||||
|
" for doc in [f for f in dpt.list_documents() if (is_modified_note(f) and is_ReadingFolder(f)) ]:\n",
|
||||||
|
" #docpath=os.path.dirname(doc['entry_path'])\n",
|
||||||
|
" #if docpath=='Document/Reading' :\n",
|
||||||
|
" data = dpt.download(doc['entry_path'])\n",
|
||||||
|
" local_path = SYNC_DIR + os.path.basename(doc['entry_path'])\n",
|
||||||
|
" with open(local_path, 'wb') as f:\n",
|
||||||
|
" f.write(data)\n",
|
||||||
|
" print('Saved {} to {}'.format(doc['entry_path'], local_path))\n",
|
||||||
|
" \n",
|
||||||
|
"def is_modified_note(doc):\n",
|
||||||
|
" import dateparser\n",
|
||||||
|
" if doc['document_type'] == 'note' or doc['document_type'] == 'normal':\n",
|
||||||
|
" local_path = SYNC_DIR + os.path.basename(doc['entry_path'])\n",
|
||||||
|
" \n",
|
||||||
|
" if not os.path.exists(local_path):\n",
|
||||||
|
" return True\n",
|
||||||
|
" else:\n",
|
||||||
|
" #print (local_path,doc['modified_date'], os.path.getmtime(local_path), dateparser.parse(doc['modified_date']).timestamp())\n",
|
||||||
|
" return os.path.getmtime(local_path) < dateparser.parse(doc['modified_date']).timestamp()\n",
|
||||||
|
" \n",
|
||||||
|
"def is_ReadingFolder(doc):\n",
|
||||||
|
" docpath=os.path.dirname(doc['entry_path'])\n",
|
||||||
|
" if docpath=='Document/Reading':\n",
|
||||||
|
" return True\n",
|
||||||
|
" else:\n",
|
||||||
|
" return False\n",
|
||||||
|
" \n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"def upload_overwrite(dpt,localpath, remotepath='Document/Reading'):\n",
|
||||||
|
" import glob, os\n",
|
||||||
|
" \n",
|
||||||
|
" files= glob.glob(localpath+'/*.pdf')\n",
|
||||||
|
" for f in files:\n",
|
||||||
|
" print (f)\n",
|
||||||
|
" dpt.upload_file(f,remotepath)\n",
|
||||||
|
" \n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"dpt=connect('192.168.0.131')\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"#dpt=connect('https://192.168.0.13')\n",
|
||||||
|
"#dpt=connect('22:6f:5d:46:3f:16')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"{'device_color': '#ffffff',\n",
|
||||||
|
" 'model_name': 'DPT-RP1',\n",
|
||||||
|
" 'serial_number': '5021254',\n",
|
||||||
|
" 'sku_code': 'U'}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"dpt.get_info()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"sync(dpt)\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 19,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"/home/dl92/Downloads/DigitalPaper/Upload/Kevin P. Murphy_Machine Learning_ A Probabilistic Perspective.pdf\n",
|
||||||
|
"/home/dl92/Downloads/DigitalPaper/Upload/John D. Kelleher_Deep Learning.pdf\n",
|
||||||
|
"/home/dl92/Downloads/DigitalPaper/Upload/Andriy Burkov_The Hundred-Page Machine Learning Book.pdf\n",
|
||||||
|
"/home/dl92/Downloads/DigitalPaper/Upload/John D. Kelleher_Fundamentals of Machine Learning for Predictive Data Analytics_ Algorithms, Worked Examples, and Case Studies.pdf\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"UPLOAD_DIR='/home/dl92/Downloads/DigitalPaper/Upload/'\n",
|
||||||
|
"upload_overwrite(dpt,UPLOAD_DIR)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 6,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"{'health': 'good',\n",
|
||||||
|
" 'icon_type': 'level_bar_4',\n",
|
||||||
|
" 'level': '95',\n",
|
||||||
|
" 'pen': '100',\n",
|
||||||
|
" 'plugged': 'not_plugged',\n",
|
||||||
|
" 'status': 'discharging'}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 6,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"dpt.get_battery()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 33,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"dpt.new_folder('Document/Work')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 29,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "ModuleNotFoundError",
|
||||||
|
"evalue": "No module named 'pypdf'",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
||||||
|
"\u001b[0;32m<ipython-input-29-913447a672fb>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mpypdf\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||||
|
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'pypdf'"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import pypdf"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 17,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"rate=0.33\n",
|
||||||
|
"price=394\n",
|
||||||
|
"motherboardasset=price-2*price*rate"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 20,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"rate=0.33\n",
|
||||||
|
"price=216\n",
|
||||||
|
"powersupplyasset=price-2*price*rate"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 23,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"73.44"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 23,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"powersupplyasset\n",
|
||||||
|
"#motherboardasset"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"celltoolbar": "Attachments",
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3.8.10 ('General')",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.8.10"
|
||||||
|
},
|
||||||
|
"toc": {
|
||||||
|
"base_numbering": 1,
|
||||||
|
"nav_menu": {},
|
||||||
|
"number_sections": true,
|
||||||
|
"sideBar": true,
|
||||||
|
"skip_h1_title": false,
|
||||||
|
"title_cell": "Table of Contents",
|
||||||
|
"title_sidebar": "Contents",
|
||||||
|
"toc_cell": false,
|
||||||
|
"toc_position": {},
|
||||||
|
"toc_section_display": true,
|
||||||
|
"toc_window_display": false
|
||||||
|
},
|
||||||
|
"vscode": {
|
||||||
|
"interpreter": {
|
||||||
|
"hash": "97f3fdd28b09b8a55d08fd0c4c2cf066e1a4715931f0fa71c8f74dcb74701738"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
71
code/misc/python/scripts/DigitalPaper Management.py
Normal file
71
code/misc/python/scripts/DigitalPaper Management.py
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from dptrp1.dptrp1 import DigitalPaper
|
||||||
|
|
||||||
|
client_id=''
|
||||||
|
key=''
|
||||||
|
SYNC_DIR = '/home/dl92/Documents/DigitalPaper/'
|
||||||
|
def connect(address=''):
|
||||||
|
"""
|
||||||
|
Loads the key and client ID to authenticate with the DPT-RP1
|
||||||
|
"""
|
||||||
|
with open('/home/dl92/.dpt-client.txt', 'r') as f:
|
||||||
|
client_id = f.readline().strip()
|
||||||
|
|
||||||
|
with open('/home/dl92/.dpt-key.txt', 'r') as f:
|
||||||
|
key = f.read()
|
||||||
|
|
||||||
|
dpt = DigitalPaper(address)
|
||||||
|
dpt.authenticate(client_id, key)
|
||||||
|
return dpt
|
||||||
|
|
||||||
|
def sync(dpt):
|
||||||
|
"""
|
||||||
|
Given an authenticated DigitalPaper instance, download all note files to a
|
||||||
|
specified directory.
|
||||||
|
"""
|
||||||
|
for doc in [f for f in dpt.list_documents() if (is_modified_note(f) and is_ReadingFolder(f)) ]:
|
||||||
|
#docpath=os.path.dirname(doc['entry_path'])
|
||||||
|
#if docpath=='Document/Reading' :
|
||||||
|
data = dpt.download(doc['entry_path'])
|
||||||
|
local_path = SYNC_DIR + os.path.basename(doc['entry_path'])
|
||||||
|
with open(local_path, 'wb') as f:
|
||||||
|
f.write(data)
|
||||||
|
print('Saved {} to {}'.format(doc['entry_path'], local_path))
|
||||||
|
|
||||||
|
def is_modified_note(doc):
|
||||||
|
import dateparser
|
||||||
|
if doc['document_type'] == 'note' or doc['document_type'] == 'normal':
|
||||||
|
local_path = SYNC_DIR + os.path.basename(doc['entry_path'])
|
||||||
|
|
||||||
|
if not os.path.exists(local_path):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
#print (local_path,doc['modified_date'], os.path.getmtime(local_path), dateparser.parse(doc['modified_date']).timestamp())
|
||||||
|
return os.path.getmtime(local_path) < dateparser.parse(doc['modified_date']).timestamp()
|
||||||
|
|
||||||
|
def is_ReadingFolder(doc):
|
||||||
|
docpath=os.path.dirname(doc['entry_path'])
|
||||||
|
if docpath=='Document/Reading':
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def upload_overwrite(dpt,localpath, remotepath='Document/Reading'):
|
||||||
|
import glob, os
|
||||||
|
dpt.new_folder(remotepath)
|
||||||
|
files= glob.glob(localpath+'/*.pdf')
|
||||||
|
for f in files:
|
||||||
|
print (f)
|
||||||
|
dpt.upload_file(f,remotepath)
|
||||||
|
|
||||||
|
def delete_foldercontent(dpt,remotepath):
|
||||||
|
[dpt.delete_document(doc['entry_path']) for doc in dpt.list_objects_in_folder(remotepath)]
|
||||||
|
|
||||||
|
|
||||||
|
dpt=connect('192.168.0.131')
|
||||||
|
#sync(dpt)
|
||||||
|
#dpt.new_folder('Document/Miri')
|
||||||
|
#upload_overwrite(dpt,SYNC_DIR+'/Upload','Document/Miri')
|
||||||
380
code/misc/python/scripts/FarsiWords.ipynb
Normal file
380
code/misc/python/scripts/FarsiWords.ipynb
Normal file
@@ -0,0 +1,380 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 37,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from selenium import webdriver\n",
|
||||||
|
"from selenium import webdriver\n",
|
||||||
|
"\n",
|
||||||
|
"browser = webdriver.Firefox(executable_path=\"/home/dl92/code/WebDriver/bin/geckodriver\")\n",
|
||||||
|
"browser.get('http://farsilookup.com/p2e/seek.jsp?lang=fa&word=+%D9%85%D8%AD%D9%88%D8%B1')\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"x=browser.find_element_by_class_name('mean-ul')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"temp=x.text"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"temp.split('\\n')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"['axis, axle, pivot']"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"temp.split('\\n')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<div>\n",
|
||||||
|
"<style scoped>\n",
|
||||||
|
" .dataframe tbody tr th:only-of-type {\n",
|
||||||
|
" vertical-align: middle;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe tbody tr th {\n",
|
||||||
|
" vertical-align: top;\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" .dataframe thead th {\n",
|
||||||
|
" text-align: right;\n",
|
||||||
|
" }\n",
|
||||||
|
"</style>\n",
|
||||||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||||||
|
" <thead>\n",
|
||||||
|
" <tr style=\"text-align: right;\">\n",
|
||||||
|
" <th></th>\n",
|
||||||
|
" <th>Unnamed: 0</th>\n",
|
||||||
|
" <th>Unnamed: 1</th>\n",
|
||||||
|
" <th>Unnamed: 2</th>\n",
|
||||||
|
" <th>Audio</th>\n",
|
||||||
|
" <th>Spelling</th>\n",
|
||||||
|
" <th>Meaning</th>\n",
|
||||||
|
" <th>Notes</th>\n",
|
||||||
|
" <th>Farsi</th>\n",
|
||||||
|
" <th>German</th>\n",
|
||||||
|
" <th>Audio (f)</th>\n",
|
||||||
|
" <th>Audio (g)</th>\n",
|
||||||
|
" <th>Tag</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>0</th>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>addition</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>1</th>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>subtraction</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2</th>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>division</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>3</th>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>multiplication</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>4</th>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>equation</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>5</th>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>equality</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" Unnamed: 0 Unnamed: 1 Unnamed: 2 Audio Spelling Meaning Notes \\\n",
|
||||||
|
"0 NaN NaN NaN NaN addition NaN NaN \n",
|
||||||
|
"1 NaN NaN NaN NaN subtraction NaN NaN \n",
|
||||||
|
"2 NaN NaN NaN NaN division NaN NaN \n",
|
||||||
|
"3 NaN NaN NaN NaN multiplication NaN NaN \n",
|
||||||
|
"4 NaN NaN NaN NaN equation NaN NaN \n",
|
||||||
|
"5 NaN NaN NaN NaN equality NaN NaN \n",
|
||||||
|
"\n",
|
||||||
|
" Farsi German Audio (f) Audio (g) Tag \n",
|
||||||
|
"0 NaN NaN NaN NaN NaN \n",
|
||||||
|
"1 NaN NaN NaN NaN NaN \n",
|
||||||
|
"2 NaN NaN NaN NaN NaN \n",
|
||||||
|
"3 NaN NaN NaN NaN NaN \n",
|
||||||
|
"4 NaN NaN NaN NaN NaN \n",
|
||||||
|
"5 NaN NaN NaN NaN NaN "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"from selenium import webdriver\n",
|
||||||
|
"from time import sleep\n",
|
||||||
|
"\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"from pathlib import Path\n",
|
||||||
|
"location=Path('/home/dl92/SynologyDrive/Kids/Miri/Spelling')\n",
|
||||||
|
"fname=location / 'Spelling Flashcards.ods'\n",
|
||||||
|
"df=pd.read_excel(fname,sheet_name=2 ,engine='odf')\n",
|
||||||
|
"df\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 6,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "SessionNotCreatedException",
|
||||||
|
"evalue": "Message: session not created: This version of ChromeDriver only supports Chrome version 87\nCurrent browser version is 92.0.4515.159 with binary path /usr/bin/google-chrome\n",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\u001b[0;31mSessionNotCreatedException\u001b[0m Traceback (most recent call last)",
|
||||||
|
"\u001b[0;32m<ipython-input-6-83301e0a41a8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mbrowser\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mwebdriver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mChrome\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'/home/dl92/code/WebDriver/bin/chromedriver'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mbrowser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'http://farsilookup.com/e2p/seek.jsp?lang=en'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mtransl\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mword\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'Spelling'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||||
|
"\u001b[0;32m~/Envs/ML/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)\u001b[0m\n\u001b[1;32m 79\u001b[0m \u001b[0mremote_server_addr\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mservice\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mservice_url\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 80\u001b[0m keep_alive=keep_alive),\n\u001b[0;32m---> 81\u001b[0;31m desired_capabilities=desired_capabilities)\n\u001b[0m\u001b[1;32m 82\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mquit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||||
|
"\u001b[0;32m~/Envs/ML/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)\u001b[0m\n\u001b[1;32m 155\u001b[0m warnings.warn(\"Please use FirefoxOptions to set browser profile\",\n\u001b[1;32m 156\u001b[0m DeprecationWarning, stacklevel=2)\n\u001b[0;32m--> 157\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstart_session\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcapabilities\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbrowser_profile\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 158\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_switch_to\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSwitchTo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_mobile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMobile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||||
|
"\u001b[0;32m~/Envs/ML/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py\u001b[0m in \u001b[0;36mstart_session\u001b[0;34m(self, capabilities, browser_profile)\u001b[0m\n\u001b[1;32m 250\u001b[0m parameters = {\"capabilities\": w3c_caps,\n\u001b[1;32m 251\u001b[0m \"desiredCapabilities\": capabilities}\n\u001b[0;32m--> 252\u001b[0;31m \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mCommand\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mNEW_SESSION\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparameters\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 253\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'sessionId'\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 254\u001b[0m \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'value'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||||
|
"\u001b[0;32m~/Envs/ML/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(self, driver_command, params)\u001b[0m\n\u001b[1;32m 319\u001b[0m \u001b[0mresponse\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcommand_executor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdriver_command\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 320\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresponse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 321\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0merror_handler\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcheck_response\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 322\u001b[0m response['value'] = self._unwrap_value(\n\u001b[1;32m 323\u001b[0m response.get('value', None))\n",
|
||||||
|
"\u001b[0;32m~/Envs/ML/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py\u001b[0m in \u001b[0;36mcheck_response\u001b[0;34m(self, response)\u001b[0m\n\u001b[1;32m 240\u001b[0m \u001b[0malert_text\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'alert'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'text'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 241\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mexception_class\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mscreen\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstacktrace\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0malert_text\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 242\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mexception_class\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mscreen\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstacktrace\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 243\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 244\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_value_or_default\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||||
|
"\u001b[0;31mSessionNotCreatedException\u001b[0m: Message: session not created: This version of ChromeDriver only supports Chrome version 87\nCurrent browser version is 92.0.4515.159 with binary path /usr/bin/google-chrome\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"browser=webdriver.Chrome('/home/dl92/code/WebDriver/bin/chromedriver')\n",
|
||||||
|
"browser.get('http://farsilookup.com/e2p/seek.jsp?lang=en')\n",
|
||||||
|
"\n",
|
||||||
|
"transl={}\n",
|
||||||
|
"for word in df['Spelling']:\n",
|
||||||
|
" try:\n",
|
||||||
|
" browser.find_element_by_id('word').clear()#.send_keys('abandoned')\n",
|
||||||
|
" browser.find_element_by_id('word').send_keys(word)\n",
|
||||||
|
" browser.find_element_by_class_name('button-search').click()\n",
|
||||||
|
" sleep(1)\n",
|
||||||
|
" res=browser.find_element_by_class_name('mean-ul')\n",
|
||||||
|
" restxt=res.text\n",
|
||||||
|
" transl[word]=restxt\n",
|
||||||
|
" except Exception as e:\n",
|
||||||
|
" transl[word]=''\n",
|
||||||
|
" continue\n",
|
||||||
|
" \n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"df['Farsi']=pd.Series(transl).values\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 61,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"fname=location / 'temp.xlsx'\n",
|
||||||
|
"df.to_excel(fname)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 8,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"{'addition': '(حساب) جمع، افزایش\\nاضافه شدن، افزودگی\\nهر چیز اضافه شده یا الحاق شده به چیز دیگر، الحاقی، اضافی\\nعنوانی که بعد از اسم فامیل می آید (مثلا : جناب آقای جان اسمیت .John Smith, Esq )',\n",
|
||||||
|
" 'subtraction': 'کاهش، تفریق، کسر سازی، کاست',\n",
|
||||||
|
" 'division': 'بخش، تقسیم، جداسازی\\nپخش، توزیع، تسهیم، حصه بری، سهم بری\\nاختلاف (عقیده یا نظر و غیره)، ناهم اندیشی\\n(به ویژه در پارلمان انگلیس) تقسیم شدن به دو یا چند دسته هنگام رای دادن\\nجدا ساز، دیواره، پاراوان، تیغه، مرز، حدفاصل،سرحد\\n(بخشی از هر چیز مثلا کشور یا اداره یا رتبه و غیره) استان، شهرستان، منطقه، دایره، فرشیم، دانگ، بخش، قسمت، دسته، طبقه،عضو، اندام (و غیره)\\n(گیاه شناسی - در برخی روش های رده بندی) شاخه (phylum هم می گویند)\\n(گل کاری و گل پروری) قلمه زنی\\n(ریاضی)تقسیم، تقسیمی، بخشی 0\\n(ارتش) لشکر، (نیروی هوایی) لشکر هوایی (متشکل از دو یا چند تیپ)، (نیروی دریایی) ناوگروه (بخشی از ناوتیپ)',\n",
|
||||||
|
" 'multiplication': '(ریاضی) عمل ضرب، بس شماری\\nزاد و ولد\\nبرافزایی، تکثیر، ازدیاد',\n",
|
||||||
|
" 'equation': 'برابر سازی، مساوی سازی، برابر پنداری\\nتساوی، برابری، توازن، تعادل، هم چندی، هم سنگی، هم پایگی، هم ترازی، هم زینگی، مشابهت\\nرجوع شود به Personal equation\\n(مجموعه ی پیچیده) پیچواره، پیچسازه\\n(ریاضی و شیمی) معادله، برابره (دوچیز که برابری آنها با نشان = مشخص می شود مثلا: H2SO4 + 2NaCl = 2HCl + Na2SO4)',\n",
|
||||||
|
" 'equality': 'برابری، مساوات\\nهم پایگی، هم چندی، هم سنگی، هم ارزی، هم زینگی\\nهمانندی، تشابه\\nهمواری، هم نواختی، همچنانی'}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 8,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"transl"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3.6.9 64-bit",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python36964bit5aad4b8392a24ab49b91cfc5ab558ab3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.6.9"
|
||||||
|
},
|
||||||
|
"toc": {
|
||||||
|
"base_numbering": 1,
|
||||||
|
"nav_menu": {},
|
||||||
|
"number_sections": true,
|
||||||
|
"sideBar": true,
|
||||||
|
"skip_h1_title": false,
|
||||||
|
"title_cell": "Table of Contents",
|
||||||
|
"title_sidebar": "Contents",
|
||||||
|
"toc_cell": false,
|
||||||
|
"toc_position": {},
|
||||||
|
"toc_section_display": true,
|
||||||
|
"toc_window_display": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
|
}
|
||||||
611
code/misc/python/scripts/KnighTour.ipynb
Normal file
611
code/misc/python/scripts/KnighTour.ipynb
Normal file
@@ -0,0 +1,611 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### Knight Moves 6\n",
|
||||||
|
"\n",
|
||||||
|
"[](https://www.janestreet.com/puzzles/october-2024.png)\n",
|
||||||
|
"\n",
|
||||||
|
"Pick **distinct positive integers** _A_, _B_, and _C_, and place them in the grid above. Your goal is to create two corner-to-corner trips — one from _a1_ to _f6_, and the other from _a6_ to _f1_ — both of which score **exactly 2024 points**.\n",
|
||||||
|
"\n",
|
||||||
|
"A “trip” consists of knight’s moves. Squares may **not** be revisited within a trip.\n",
|
||||||
|
"\n",
|
||||||
|
"The “score” for a trip is calculated as follows:\n",
|
||||||
|
"\n",
|
||||||
|
"- Start with _A_ points.\n",
|
||||||
|
"- Every time you make a move:\n",
|
||||||
|
" - if your move is between two _different_ integers, **multiply** your score by the value you are moving to;\n",
|
||||||
|
" - otherwise, **increment** your score by the value you are moving to.\n",
|
||||||
|
"\n",
|
||||||
|
"Can you find positive integers _A_, _B_, and _C_, as well as a pair of trips, that satisfy the criteria above? How low can you get _A_ + _B_ + _C_?\n",
|
||||||
|
"\n",
|
||||||
|
"Please format your entry by concatenating your values for _A_, _B_, and _C_, followed by your _a1_-to-_f6_ tour, followed by your _a6_-to-_f1_ tour. For example, “1,2,253,a1,b3,c5,d3,f4,d5,f6,a6,c5,a4,b2,c4,d2,f1” would be a properly formatted entry.\n",
|
||||||
|
"\n",
|
||||||
|
"To qualify for the leaderboard your value for _A_ + _B_ + _C_ must be **less than 50**."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"#code\n",
|
||||||
|
"\n",
|
||||||
|
"from IPython.core.interactiveshell import InteractiveShell\n",
|
||||||
|
"InteractiveShell.ast_node_interactivity = \"all\"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"import numpy as np\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"def encode_scoregrid(path:str):\n",
|
||||||
|
" return { (j,i):x+str(y) for i,x in enumerate(['a','b','c','d','e','f']) for j,y in enumerate([1,2,3,4,5,6][::-1])}\n",
|
||||||
|
"\n",
|
||||||
|
"def decode_scoregrid():\n",
|
||||||
|
" return { x+str(y):(j,i) for i,x in enumerate(['a','b','c','d','e','f']) for j,y in enumerate([1,2,3,4,5,6][::-1])}\n",
|
||||||
|
"\n",
|
||||||
|
"def calc_score_tuple(tuplepaths,scoregrid):\n",
|
||||||
|
" \n",
|
||||||
|
" prevpos=None\n",
|
||||||
|
" score=None\n",
|
||||||
|
" for i,pos in enumerate(tuplepaths):\n",
|
||||||
|
" \n",
|
||||||
|
" if i==0:\n",
|
||||||
|
" prevpos=pos\n",
|
||||||
|
" score=scoregrid[pos]\n",
|
||||||
|
" elif scoregrid[prevpos]==scoregrid[pos]:\n",
|
||||||
|
" score+=scoregrid[pos]\n",
|
||||||
|
" prevpos=pos\n",
|
||||||
|
" else:\n",
|
||||||
|
" score*=scoregrid[pos]\n",
|
||||||
|
" prevpos=pos\n",
|
||||||
|
"\n",
|
||||||
|
" return score\n",
|
||||||
|
" \n",
|
||||||
|
"def calc_score_str(path,scoregrid:str):\n",
|
||||||
|
" decode=decode_scoregrid()\n",
|
||||||
|
" path = path.split(',')\n",
|
||||||
|
"\n",
|
||||||
|
" return calc_score_tuple([decode[x] for x in path],scoregrid)\n",
|
||||||
|
" \n",
|
||||||
|
" \n",
|
||||||
|
" \n",
|
||||||
|
"\n",
|
||||||
|
"class KnightTour:\n",
|
||||||
|
"\n",
|
||||||
|
" def __init__(self,pos,prevpos,posstr,score,tours,nmoves):\n",
|
||||||
|
"\n",
|
||||||
|
" \n",
|
||||||
|
" self.currpos=pos\n",
|
||||||
|
" self.prevpos= prevpos\n",
|
||||||
|
" self.curposstr=posstr\n",
|
||||||
|
" self.currscore=score\n",
|
||||||
|
" self.tours=tours\n",
|
||||||
|
" self.nummoves=nmoves\n",
|
||||||
|
" \n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" def __repr__(self):\n",
|
||||||
|
" return f'tour={self.tours}, score={self.currscore}'\n",
|
||||||
|
"\n",
|
||||||
|
"class Grid:\n",
|
||||||
|
"\n",
|
||||||
|
" def __init__(self,dims=(6,6)):\n",
|
||||||
|
" \n",
|
||||||
|
"\n",
|
||||||
|
" xlabel_i2key = {0:'a',1:'b',2:'c',3:'d',4:'e',5:'f'}\n",
|
||||||
|
" ylabel_i2key = {0:6,1:5,2:4,3:3,4:2,5:1}\n",
|
||||||
|
" xlabel_key2i ={v:k for k,v in xlabel_i2key.items()}\n",
|
||||||
|
" ylabel_key2i ={v:k for k,v in ylabel_i2key.items()}\n",
|
||||||
|
"\n",
|
||||||
|
" #construct keys for the grid\n",
|
||||||
|
" self.key_gindex={(x+str(y)):(xlabel_key2i[x],ylabel_key2i[y]) for x in ['a','b','c','d','e','f'] for y in [1,2,3,4,5,6]}\n",
|
||||||
|
" self.gindex_key ={v:k for k,v in self.key_gindex.items()}\n",
|
||||||
|
"\n",
|
||||||
|
" #kight moves on grid\n",
|
||||||
|
" self.moves = [(2,1),(1,2),(-1,2),(-2,1),(-2,-1),(-1,-2),(1,-2),(2,-1)]\n",
|
||||||
|
"\n",
|
||||||
|
" self.dims = dims\n",
|
||||||
|
" self.successfull_tours = None\n",
|
||||||
|
" self.ls_knighttours = None\n",
|
||||||
|
" self.score=np.zeros(dtype='int',shape=dims)\n",
|
||||||
|
"\n",
|
||||||
|
" def scoregrid (self, A,B,C):\n",
|
||||||
|
"\n",
|
||||||
|
" self.score[:,:]=B \n",
|
||||||
|
" self.score[:,0]=A\n",
|
||||||
|
" self.score[-4:,1]=A\n",
|
||||||
|
" self.score[-2:,2]=A\n",
|
||||||
|
" self.score[:,-1]=C\n",
|
||||||
|
" self.score[:4,-2]=C\n",
|
||||||
|
" self.score[:2,-3]=C\n",
|
||||||
|
" #return self.score\n",
|
||||||
|
" \n",
|
||||||
|
" def calcscore_at_nextpos(self,prev_score,init_pos,next_pos):\n",
|
||||||
|
" #care numpy array indexing, row first then column\n",
|
||||||
|
" #pos is x,y == (column,row) therefore reverse indexing\n",
|
||||||
|
"\n",
|
||||||
|
" if self.score[init_pos[::-1]]==self.score[next_pos[::-1]]:\n",
|
||||||
|
" return prev_score+self.score[next_pos[::-1]]\n",
|
||||||
|
" else:\n",
|
||||||
|
" return prev_score*self.score[next_pos[::-1]]\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" score = prev_score[next_pos] - prev_score[init_pos]\n",
|
||||||
|
" return score\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" def tour(self,a,b,c,init_pos:tuple,dest_pos:tuple,numsteps:int):\n",
|
||||||
|
" \n",
|
||||||
|
" self.successfull_tours = None\n",
|
||||||
|
" self.ls_knighttours = None\n",
|
||||||
|
" self.scoregrid(a,b,c)\n",
|
||||||
|
" score=a\n",
|
||||||
|
" posstr = self.gindex_key[init_pos]\n",
|
||||||
|
" ls_knighttours=KnightTour(init_pos,init_pos,posstr,score,posstr,1)\n",
|
||||||
|
" \n",
|
||||||
|
" self.run_knight_tours(numsteps,dest_pos,1,[ls_knighttours],[])\n",
|
||||||
|
" #print(self.successfull_tours)\n",
|
||||||
|
" return (pd.DataFrame([(t.tours,t.nummoves,t.currscore) for t in self.successfull_tours],\n",
|
||||||
|
" columns=['tour','nmoves','score'])\n",
|
||||||
|
" .assign(score=lambda df: df.apply(lambda r: calc_score_str(r['tour'],self.score),axis=1))\n",
|
||||||
|
" .sort_values(by='score',ascending=False)\n",
|
||||||
|
" .pipe(lambda x: x[x.score==2024])\n",
|
||||||
|
" .head(1)\n",
|
||||||
|
" )\n",
|
||||||
|
" \n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" def run_knight_tours(self,numsteps,dest:tuple,iter,ls_knighttours:list,successfull_tours:list):\n",
|
||||||
|
" #knight move in x,y coordinate system different to indexing of arrays!\n",
|
||||||
|
" \n",
|
||||||
|
" if iter == numsteps:\n",
|
||||||
|
" self.ls_knighttours=ls_knighttours\n",
|
||||||
|
" self.successfull_tours=successfull_tours\n",
|
||||||
|
" return \n",
|
||||||
|
" \n",
|
||||||
|
" newscore=0\n",
|
||||||
|
" newls_knighttours = [] \n",
|
||||||
|
" for aknighttour in ls_knighttours:\n",
|
||||||
|
"\n",
|
||||||
|
" prevpos= aknighttour.prevpos\n",
|
||||||
|
" pos= aknighttour.currpos\n",
|
||||||
|
" score= aknighttour.currscore\n",
|
||||||
|
"\n",
|
||||||
|
" #check if the tour is complete!\n",
|
||||||
|
" #if pos[0]==dest[0] and pos[1]==dest[1]: #reached f6 f1\n",
|
||||||
|
" # successfull_tours.append(aknighttour)\n",
|
||||||
|
" # continue\n",
|
||||||
|
" \n",
|
||||||
|
" for move in self.moves: #all possible moves\n",
|
||||||
|
" x_new = pos[0]+move[0]\n",
|
||||||
|
" y_new = pos[1]+move[1]\n",
|
||||||
|
"\n",
|
||||||
|
" \n",
|
||||||
|
" if (x_new >= 0 and x_new< self.dims[0] and y_new >= 0 and y_new < self.dims[1]): #check if the move is valid \n",
|
||||||
|
" \n",
|
||||||
|
" #make sure new move does not go backwards!\n",
|
||||||
|
" if (x_new == prevpos[0] and y_new == prevpos[1]):\n",
|
||||||
|
" continue\n",
|
||||||
|
" \n",
|
||||||
|
"\n",
|
||||||
|
" #newscore=self.calcscore_at_nextpos(score,(pos[0],pos[1]),(x_new,y_new))\n",
|
||||||
|
" posstr = self.gindex_key[(x_new,y_new)]\n",
|
||||||
|
"\n",
|
||||||
|
" #now for each valid move, create corresponding paths/score\n",
|
||||||
|
" updatedtour=aknighttour.tours +','+posstr\n",
|
||||||
|
"\n",
|
||||||
|
" newknighttour=KnightTour((x_new,y_new),pos,posstr,newscore,updatedtour,aknighttour.nummoves+1)\n",
|
||||||
|
" if x_new==dest[0] and y_new==dest[1]: #reached f6 f1\n",
|
||||||
|
" successfull_tours.append(newknighttour)\n",
|
||||||
|
" else: \n",
|
||||||
|
" newls_knighttours.append(newknighttour)\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" return self.run_knight_tours(numsteps,dest,iter+1,newls_knighttours,successfull_tours)\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"'a1,b3,d2,c4,d6,e4,f6'"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"N=7\n",
|
||||||
|
"gobj=Grid()\n",
|
||||||
|
"res_a1_f6=gobj.tour(1,2,253,(0,5),(5,0),N)\n",
|
||||||
|
"\n",
|
||||||
|
"res_a6_f1=gobj.tour(1,2,253,(0,0),(5,5),N)\n",
|
||||||
|
"\n",
|
||||||
|
"res_a1_f6.iloc[0,0]\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 8,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"1 2 3 6\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"\n",
|
||||||
|
"gobj=Grid()\n",
|
||||||
|
"N=15\n",
|
||||||
|
"\n",
|
||||||
|
"counter=0\n",
|
||||||
|
"\n",
|
||||||
|
"outputs=[]\n",
|
||||||
|
"scores=[]\n",
|
||||||
|
"ids=[]\n",
|
||||||
|
"for i in range(1,51):\n",
|
||||||
|
" for j in range(1,51):\n",
|
||||||
|
" for k in range(1,51):\n",
|
||||||
|
" if (i !=j) and (j!=k) and (i!=k):\n",
|
||||||
|
" sum=i+j+k\n",
|
||||||
|
" if sum<=6:\n",
|
||||||
|
" #print(counter)\n",
|
||||||
|
" print(i,j,k,sum)\n",
|
||||||
|
" res_a6_f1=gobj.tour(i,j,k,(0,0),(5,5),N)\n",
|
||||||
|
" res_a1_f6=gobj.tour(i,j,k,(0,5),(5,0),N)\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
" if res_a6_f1.empty==False and res_a1_f6.empty==False:\n",
|
||||||
|
" if res_a1_f6.iloc[0,2]==res_a1_f6.iloc[0,2]:\n",
|
||||||
|
" op=f'{i},{j},{k},{res_a1_f6.iloc[0,0]},{res_a6_f1.iloc[0,0]}'\n",
|
||||||
|
" ids.append(counter)\n",
|
||||||
|
" scores.append(sum)\n",
|
||||||
|
" outputs.append(op)\n",
|
||||||
|
" print(counter,sum,op) \n",
|
||||||
|
" counter+=1\n",
|
||||||
|
"\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 17,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"[]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 17,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"gobj.tour(40,5,6,(0,0),(5,5),4)\n",
|
||||||
|
"gobj.successfull_tours"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"#code\n",
|
||||||
|
"score=np.zeros(dtype='int',shape=(6,6))\n",
|
||||||
|
"\n",
|
||||||
|
"def encode_scoregrid(path:str):\n",
|
||||||
|
" return { (j,i):x+str(y) for i,x in enumerate(['a','b','c','d','e','f']) for j,y in enumerate([1,2,3,4,5,6][::-1])}\n",
|
||||||
|
"\n",
|
||||||
|
"def decode_scoregrid():\n",
|
||||||
|
" return { x+str(y):(j,i) for i,x in enumerate(['a','b','c','d','e','f']) for j,y in enumerate([1,2,3,4,5,6][::-1])}\n",
|
||||||
|
" \n",
|
||||||
|
"def f_scoregrid (A,B,C):\n",
|
||||||
|
"\n",
|
||||||
|
" score[:,:]=B \n",
|
||||||
|
" score[:,0]=A\n",
|
||||||
|
" score[-4:,1]=A\n",
|
||||||
|
" score[-2:,2]=A\n",
|
||||||
|
" score[:,-1]=C\n",
|
||||||
|
" score[:4,-2]=C\n",
|
||||||
|
" score[:2,-3]=C\n",
|
||||||
|
" return score\n",
|
||||||
|
"\n",
|
||||||
|
"scoregrid=f_scoregrid(1,2,253)\n",
|
||||||
|
"\n",
|
||||||
|
"def calc_score_tuple(tuplepaths,scoregrid):\n",
|
||||||
|
" \n",
|
||||||
|
" prevpos=None\n",
|
||||||
|
" score=None\n",
|
||||||
|
" for i,pos in enumerate(tuplepaths):\n",
|
||||||
|
" \n",
|
||||||
|
" if i==0:\n",
|
||||||
|
" prevpos=pos\n",
|
||||||
|
" score=scoregrid[pos]\n",
|
||||||
|
" elif scoregrid[prevpos]==scoregrid[pos]:\n",
|
||||||
|
" score+=scoregrid[pos]\n",
|
||||||
|
" prevpos=pos\n",
|
||||||
|
" else:\n",
|
||||||
|
" score*=scoregrid[pos]\n",
|
||||||
|
" prevpos=pos\n",
|
||||||
|
"\n",
|
||||||
|
" return score\n",
|
||||||
|
" \n",
|
||||||
|
"def calc_score_str(path,scoregrid:str):\n",
|
||||||
|
" decode=decode_scoregrid()\n",
|
||||||
|
" path = path.split(',')\n",
|
||||||
|
"\n",
|
||||||
|
" return calc_score_tuple([decode[x] for x in path],scoregrid)\n",
|
||||||
|
" \n",
|
||||||
|
" \n",
|
||||||
|
" \n",
|
||||||
|
" # return res "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "NameError",
|
||||||
|
"evalue": "name 'calc_score' is not defined",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
||||||
|
"Cell \u001b[0;32mIn[3], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m#a6,b4,c6,d4,f3,d2,e4,f6, score=111\u001b[39;00m\n\u001b[1;32m 2\u001b[0m scoregrid\u001b[38;5;241m=\u001b[39mf_scoregrid(\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m253\u001b[39m)\n\u001b[0;32m----> 4\u001b[0m \u001b[43mcalc_score\u001b[49m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124ma6,b4,c6,d4,f3,d2,e4,f6\u001b[39m\u001b[38;5;124m'\u001b[39m,scoregrid)\n",
|
||||||
|
"\u001b[0;31mNameError\u001b[0m: name 'calc_score' is not defined"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"#a6,b4,c6,d4,f3,d2,e4,f6, score=111\n",
|
||||||
|
"scoregrid=f_scoregrid(1,2,253)\n",
|
||||||
|
"\n",
|
||||||
|
"calc_score('a6,b4,c6,d4,f3,d2,e4,f6',scoregrid)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 38,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"[np.int64(2024),\n",
|
||||||
|
" np.int64(2024),\n",
|
||||||
|
" np.int64(2024),\n",
|
||||||
|
" np.int64(2024),\n",
|
||||||
|
" np.int64(2024),\n",
|
||||||
|
" np.int64(2024),\n",
|
||||||
|
" np.int64(2024)]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 38,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"scores=['a6,b4,a2,c3,d5,e3,f1',\n",
|
||||||
|
"'a6,c5,b3,a5,c4,d2,f1',\n",
|
||||||
|
"'a6,b4,c2,d4,f5,e3,f1',\n",
|
||||||
|
"'a6,b4,c6,d4,f5,e3,f1',\n",
|
||||||
|
"'a6,c5,a4,c3,b1,d2,f1',\n",
|
||||||
|
"'a6,c5,a4,b2,c4,d2,f1',\n",
|
||||||
|
"'a6,c5,a4,b6,c4,d2,f1'\n",
|
||||||
|
"]\n",
|
||||||
|
"\n",
|
||||||
|
"[calc_score_str(x,scoregrid) for x in scores]\n",
|
||||||
|
"\n",
|
||||||
|
"#calc_score_str('a1,b3,c5,d3,f4,d5,f6',scoregrid)\n",
|
||||||
|
"#calc_score_str('a6,c5,a4,b2,c4,d2,f1',scoregrid)\n",
|
||||||
|
"#calc_score_tuple([(5, 0), (3, 1), (1, 2), (3, 3), (2, 5), (1, 3), (0, 5)],scoregrid)\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"np.int64(2024)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"np.int64(2024)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"scoregrid=f_scoregrid(1,5,2)\n",
|
||||||
|
"calc_score_str('a1,c2,d4,f3,d2,f1,e3,d1,f2,e4,f6',scoregrid)\n",
|
||||||
|
"calc_score_str('a6,c5,d3,e5,c4,d6,e4,c3,d5,e3,f1',scoregrid)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# joojoo score"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"np.int64(2024)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"np.int64(2024)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import numpy as np\n",
|
||||||
|
"scoregrid=f_scoregrid(3,1,2)\n",
|
||||||
|
"calc_score_str('a1,c2,e3,c4,a5,c6,d4,b3,c5,d3,b2,d1,c3,b1,d2,e4,f6',scoregrid)\n",
|
||||||
|
"\n",
|
||||||
|
"calc_score_str('a6,b4,d5,c3,a4,c5,d3,c1,e2,d4,b3,d2,c4,b2,d1,e3,f1',scoregrid)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# joojoo score v2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 7,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"np.int64(2024)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 7,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"np.int64(2024)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 7,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import numpy as np\n",
|
||||||
|
"scoregrid=f_scoregrid(1,3,2)\n",
|
||||||
|
"calc_score_str('a1,c2,b4,c6,e5,d3,f2,e4,d6,c4,a3,b1,c3,d5,f6',scoregrid)\n",
|
||||||
|
"\n",
|
||||||
|
"calc_score_str('a6,b4,c2,e1,f3,d4,f5,d6,e4,c3,b1,a3,c4,e3,f1',scoregrid)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 74,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"[(5, 0), (3, 1), (1, 2), (3, 3), (2, 5), (1, 3), (0, 5)]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 74,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"[(0, 0), (1, 2), (2, 0), (4, 1), (2, 2), (4, 3), (5, 5)]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 74,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"decode=decode_scoregrid()\n",
|
||||||
|
"[decode[k] for k in 'a1,b3,c5,d3,f4,d5,f6'.split(',')]\n",
|
||||||
|
"[decode[k] for k in 'a6,c5,a4,b2,c4,d2,f1'.split(',')]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "General",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.11.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
14
code/misc/python/scripts/MITM/.gitignore
vendored
Normal file
14
code/misc/python/scripts/MITM/.gitignore
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
*.pyc
|
||||||
|
*.db
|
||||||
|
*.python-version
|
||||||
|
/.quarto/
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
719
code/misc/python/scripts/MITM/Terms-to-Block.csv
Normal file
719
code/misc/python/scripts/MITM/Terms-to-Block.csv
Normal file
@@ -0,0 +1,719 @@
|
|||||||
|
anal
|
||||||
|
analprobe
|
||||||
|
anilingus
|
||||||
|
anus
|
||||||
|
areola
|
||||||
|
areole
|
||||||
|
arian
|
||||||
|
aryan
|
||||||
|
ass
|
||||||
|
assbang
|
||||||
|
assbanged
|
||||||
|
assbangs
|
||||||
|
asses
|
||||||
|
assfuck
|
||||||
|
assfucker
|
||||||
|
assh0le
|
||||||
|
asshat
|
||||||
|
assho1e
|
||||||
|
ass hole
|
||||||
|
assholes
|
||||||
|
assmaster
|
||||||
|
assmunch
|
||||||
|
asswipe
|
||||||
|
asswipes
|
||||||
|
azazel
|
||||||
|
azz
|
||||||
|
b1tch
|
||||||
|
babe
|
||||||
|
babes
|
||||||
|
ballsack
|
||||||
|
bang
|
||||||
|
banger
|
||||||
|
barf
|
||||||
|
bastard
|
||||||
|
bastards
|
||||||
|
bawdy
|
||||||
|
beaner
|
||||||
|
beardedclam
|
||||||
|
beastiality
|
||||||
|
beatch
|
||||||
|
beater
|
||||||
|
beaver
|
||||||
|
beer
|
||||||
|
beeyotch
|
||||||
|
beotch
|
||||||
|
biatch
|
||||||
|
bigtits
|
||||||
|
big tits
|
||||||
|
bimbo
|
||||||
|
bitch
|
||||||
|
bitched
|
||||||
|
bitches
|
||||||
|
bitchy
|
||||||
|
blow job
|
||||||
|
blow
|
||||||
|
blowjob
|
||||||
|
blowjobs
|
||||||
|
bod
|
||||||
|
bodily
|
||||||
|
boink
|
||||||
|
bollock
|
||||||
|
bollocks
|
||||||
|
bollok
|
||||||
|
bone
|
||||||
|
boned
|
||||||
|
boner
|
||||||
|
boners
|
||||||
|
bong
|
||||||
|
boob
|
||||||
|
boobies
|
||||||
|
boobs
|
||||||
|
booby
|
||||||
|
booger
|
||||||
|
bookie
|
||||||
|
bootee
|
||||||
|
bootie
|
||||||
|
booty
|
||||||
|
booze
|
||||||
|
boozer
|
||||||
|
boozy
|
||||||
|
bosom
|
||||||
|
bosomy
|
||||||
|
bowel
|
||||||
|
bowels
|
||||||
|
bra
|
||||||
|
brassiere
|
||||||
|
breast
|
||||||
|
breasts
|
||||||
|
bugger
|
||||||
|
bukkake
|
||||||
|
bullshit
|
||||||
|
bull shit
|
||||||
|
bullshits
|
||||||
|
bullshitted
|
||||||
|
bullturds
|
||||||
|
bung
|
||||||
|
busty
|
||||||
|
butt
|
||||||
|
butt fuck
|
||||||
|
buttfuck
|
||||||
|
buttfucker
|
||||||
|
buttfucker
|
||||||
|
buttplug
|
||||||
|
c.0.c.k
|
||||||
|
c.o.c.k.
|
||||||
|
c.u.n.t
|
||||||
|
c0ck
|
||||||
|
c-0-c-k
|
||||||
|
caca
|
||||||
|
cahone
|
||||||
|
cameltoe
|
||||||
|
carpetmuncher
|
||||||
|
cawk
|
||||||
|
cervix
|
||||||
|
chinc
|
||||||
|
chincs
|
||||||
|
chink
|
||||||
|
chink
|
||||||
|
chode
|
||||||
|
chodes
|
||||||
|
cl1t
|
||||||
|
climax
|
||||||
|
clit
|
||||||
|
clitoris
|
||||||
|
clitorus
|
||||||
|
clits
|
||||||
|
clitty
|
||||||
|
cocain
|
||||||
|
cocaine
|
||||||
|
cock
|
||||||
|
c-o-c-k
|
||||||
|
cockblock
|
||||||
|
cockholster
|
||||||
|
cockknocker
|
||||||
|
cocks
|
||||||
|
cocksmoker
|
||||||
|
cocksucker
|
||||||
|
cock sucker
|
||||||
|
coital
|
||||||
|
commie
|
||||||
|
condom
|
||||||
|
coon
|
||||||
|
coons
|
||||||
|
corksucker
|
||||||
|
crabs
|
||||||
|
crack
|
||||||
|
cracker
|
||||||
|
crackwhore
|
||||||
|
crap
|
||||||
|
crappy
|
||||||
|
cum
|
||||||
|
cummin
|
||||||
|
cumming
|
||||||
|
cumshot
|
||||||
|
cumshots
|
||||||
|
cumslut
|
||||||
|
cumstain
|
||||||
|
cunilingus
|
||||||
|
cunnilingus
|
||||||
|
cunny
|
||||||
|
cunt
|
||||||
|
cunt
|
||||||
|
c-u-n-t
|
||||||
|
cuntface
|
||||||
|
cunthunter
|
||||||
|
cuntlick
|
||||||
|
cuntlicker
|
||||||
|
cunts
|
||||||
|
d0ng
|
||||||
|
d0uch3
|
||||||
|
d0uche
|
||||||
|
d1ck
|
||||||
|
d1ld0
|
||||||
|
d1ldo
|
||||||
|
dago
|
||||||
|
dagos
|
||||||
|
dammit
|
||||||
|
damn
|
||||||
|
damned
|
||||||
|
damnit
|
||||||
|
dawgie-style
|
||||||
|
dick
|
||||||
|
dickbag
|
||||||
|
dickdipper
|
||||||
|
dickface
|
||||||
|
dickflipper
|
||||||
|
dickhead
|
||||||
|
dickheads
|
||||||
|
dickish
|
||||||
|
dick-ish
|
||||||
|
dickripper
|
||||||
|
dicksipper
|
||||||
|
dickweed
|
||||||
|
dickwhipper
|
||||||
|
dickzipper
|
||||||
|
diddle
|
||||||
|
dike
|
||||||
|
dildo
|
||||||
|
dildos
|
||||||
|
diligaf
|
||||||
|
dillweed
|
||||||
|
dimwit
|
||||||
|
dingle
|
||||||
|
dipship
|
||||||
|
doggie-style
|
||||||
|
doggy-style
|
||||||
|
dong
|
||||||
|
doofus
|
||||||
|
doosh
|
||||||
|
dopey
|
||||||
|
douch3
|
||||||
|
douche
|
||||||
|
douchebag
|
||||||
|
douchebags
|
||||||
|
douchey
|
||||||
|
drunk
|
||||||
|
dumass
|
||||||
|
dumbass
|
||||||
|
dumbasses
|
||||||
|
dummy
|
||||||
|
dyke
|
||||||
|
dykes
|
||||||
|
ejaculate
|
||||||
|
enlargement
|
||||||
|
erect
|
||||||
|
erection
|
||||||
|
erotic
|
||||||
|
essohbee
|
||||||
|
extacy
|
||||||
|
extasy
|
||||||
|
f.u.c.k
|
||||||
|
fack
|
||||||
|
fag
|
||||||
|
fagg
|
||||||
|
fagged
|
||||||
|
faggit
|
||||||
|
faggot
|
||||||
|
fagot
|
||||||
|
fags
|
||||||
|
faig
|
||||||
|
faigt
|
||||||
|
fannybandit
|
||||||
|
fart
|
||||||
|
fartknocker
|
||||||
|
fat
|
||||||
|
felch
|
||||||
|
felcher
|
||||||
|
felching
|
||||||
|
fellate
|
||||||
|
fellatio
|
||||||
|
feltch
|
||||||
|
feltcher
|
||||||
|
fisted
|
||||||
|
fisting
|
||||||
|
fisty
|
||||||
|
floozy
|
||||||
|
foad
|
||||||
|
fondle
|
||||||
|
foobar
|
||||||
|
foreskin
|
||||||
|
freex
|
||||||
|
frigg
|
||||||
|
frigga
|
||||||
|
fubar
|
||||||
|
fuck
|
||||||
|
f-u-c-k
|
||||||
|
fuckass
|
||||||
|
fucked
|
||||||
|
fucked
|
||||||
|
fucker
|
||||||
|
fuckface
|
||||||
|
fuckin
|
||||||
|
fucking
|
||||||
|
fucknugget
|
||||||
|
fucknut
|
||||||
|
fuckoff
|
||||||
|
fucks
|
||||||
|
fucktard
|
||||||
|
fuck-tard
|
||||||
|
fuckup
|
||||||
|
fuckwad
|
||||||
|
fuckwit
|
||||||
|
fudgepacker
|
||||||
|
fuk
|
||||||
|
fvck
|
||||||
|
fxck
|
||||||
|
gae
|
||||||
|
gai
|
||||||
|
ganja
|
||||||
|
gay
|
||||||
|
gays
|
||||||
|
gey
|
||||||
|
gfy
|
||||||
|
ghay
|
||||||
|
ghey
|
||||||
|
gigolo
|
||||||
|
glans
|
||||||
|
goatse
|
||||||
|
godamn
|
||||||
|
godamnit
|
||||||
|
goddam
|
||||||
|
goddammit
|
||||||
|
goddamn
|
||||||
|
goldenshower
|
||||||
|
gonad
|
||||||
|
gonads
|
||||||
|
gook
|
||||||
|
gooks
|
||||||
|
gringo
|
||||||
|
gspot
|
||||||
|
g-spot
|
||||||
|
gtfo
|
||||||
|
guido
|
||||||
|
h0m0
|
||||||
|
h0mo
|
||||||
|
handjob
|
||||||
|
hard on
|
||||||
|
he11
|
||||||
|
hebe
|
||||||
|
heeb
|
||||||
|
hell
|
||||||
|
hemp
|
||||||
|
heroin
|
||||||
|
herp
|
||||||
|
herpes
|
||||||
|
herpy
|
||||||
|
hitler
|
||||||
|
hiv
|
||||||
|
hobag
|
||||||
|
hom0
|
||||||
|
homey
|
||||||
|
homo
|
||||||
|
homoey
|
||||||
|
honky
|
||||||
|
hooch
|
||||||
|
hookah
|
||||||
|
hooker
|
||||||
|
hoor
|
||||||
|
hootch
|
||||||
|
hooter
|
||||||
|
hooters
|
||||||
|
horny
|
||||||
|
hump
|
||||||
|
humped
|
||||||
|
humping
|
||||||
|
hussy
|
||||||
|
hymen
|
||||||
|
inbred
|
||||||
|
incest
|
||||||
|
injun
|
||||||
|
j3rk0ff
|
||||||
|
jackass
|
||||||
|
jackhole
|
||||||
|
jackoff
|
||||||
|
jap
|
||||||
|
japs
|
||||||
|
jerk
|
||||||
|
jerk0ff
|
||||||
|
jerked
|
||||||
|
jerkoff
|
||||||
|
jism
|
||||||
|
jiz
|
||||||
|
jizm
|
||||||
|
jizz
|
||||||
|
jizzed
|
||||||
|
junkie
|
||||||
|
junky
|
||||||
|
kike
|
||||||
|
kikes
|
||||||
|
kill
|
||||||
|
kinky
|
||||||
|
kkk
|
||||||
|
klan
|
||||||
|
knobend
|
||||||
|
kooch
|
||||||
|
kooches
|
||||||
|
kootch
|
||||||
|
kraut
|
||||||
|
kyke
|
||||||
|
labia
|
||||||
|
lech
|
||||||
|
leper
|
||||||
|
lesbians
|
||||||
|
lesbo
|
||||||
|
lesbos
|
||||||
|
lez
|
||||||
|
lezbian
|
||||||
|
lezbians
|
||||||
|
lezbo
|
||||||
|
lezbos
|
||||||
|
lezzie
|
||||||
|
lezzies
|
||||||
|
lezzy
|
||||||
|
lmao
|
||||||
|
lmfao
|
||||||
|
loin
|
||||||
|
loins
|
||||||
|
lube
|
||||||
|
lusty
|
||||||
|
mams
|
||||||
|
massa
|
||||||
|
masterbate
|
||||||
|
masterbating
|
||||||
|
masterbation
|
||||||
|
masturbate
|
||||||
|
masturbating
|
||||||
|
masturbation
|
||||||
|
maxi
|
||||||
|
menses
|
||||||
|
menstruate
|
||||||
|
menstruation
|
||||||
|
meth
|
||||||
|
m-fucking
|
||||||
|
mofo
|
||||||
|
molest
|
||||||
|
moolie
|
||||||
|
moron
|
||||||
|
motherfucka
|
||||||
|
motherfucker
|
||||||
|
motherfucking
|
||||||
|
mtherfucker
|
||||||
|
mthrfucker
|
||||||
|
mthrfucking
|
||||||
|
muff
|
||||||
|
muffdiver
|
||||||
|
murder
|
||||||
|
muthafuckaz
|
||||||
|
muthafucker
|
||||||
|
mutherfucker
|
||||||
|
mutherfucking
|
||||||
|
muthrfucking
|
||||||
|
nad
|
||||||
|
nads
|
||||||
|
naked
|
||||||
|
napalm
|
||||||
|
nappy
|
||||||
|
nazi
|
||||||
|
nazism
|
||||||
|
negro
|
||||||
|
nigga
|
||||||
|
niggah
|
||||||
|
niggas
|
||||||
|
niggaz
|
||||||
|
nigger
|
||||||
|
nigger
|
||||||
|
niggers
|
||||||
|
niggle
|
||||||
|
niglet
|
||||||
|
nimrod
|
||||||
|
ninny
|
||||||
|
nipple
|
||||||
|
nooky
|
||||||
|
nympho
|
||||||
|
opiate
|
||||||
|
opium
|
||||||
|
oral
|
||||||
|
orally
|
||||||
|
organ
|
||||||
|
orgasm
|
||||||
|
orgasmic
|
||||||
|
orgies
|
||||||
|
orgy
|
||||||
|
ovary
|
||||||
|
ovum
|
||||||
|
ovums
|
||||||
|
p.u.s.s.y.
|
||||||
|
paddy
|
||||||
|
paki
|
||||||
|
pantie
|
||||||
|
panties
|
||||||
|
panty
|
||||||
|
pastie
|
||||||
|
pasty
|
||||||
|
pcp
|
||||||
|
pecker
|
||||||
|
pedo
|
||||||
|
pedophile
|
||||||
|
pedophilia
|
||||||
|
pedophiliac
|
||||||
|
pee
|
||||||
|
peepee
|
||||||
|
penetrate
|
||||||
|
penetration
|
||||||
|
penial
|
||||||
|
penile
|
||||||
|
penis
|
||||||
|
perversion
|
||||||
|
peyote
|
||||||
|
phalli
|
||||||
|
phallic
|
||||||
|
phuck
|
||||||
|
pillowbiter
|
||||||
|
pimp
|
||||||
|
pinko
|
||||||
|
piss
|
||||||
|
pissed
|
||||||
|
pissoff
|
||||||
|
piss-off
|
||||||
|
pms
|
||||||
|
polack
|
||||||
|
pollock
|
||||||
|
poon
|
||||||
|
poontang
|
||||||
|
porn
|
||||||
|
porno
|
||||||
|
pornography
|
||||||
|
pot
|
||||||
|
potty
|
||||||
|
prick
|
||||||
|
prig
|
||||||
|
prostitute
|
||||||
|
prude
|
||||||
|
pube
|
||||||
|
pubic
|
||||||
|
pubis
|
||||||
|
punkass
|
||||||
|
punky
|
||||||
|
puss
|
||||||
|
pussies
|
||||||
|
pussy
|
||||||
|
pussypounder
|
||||||
|
puto
|
||||||
|
queaf
|
||||||
|
queef
|
||||||
|
queef
|
||||||
|
queer
|
||||||
|
queero
|
||||||
|
queers
|
||||||
|
quicky
|
||||||
|
quim
|
||||||
|
racy
|
||||||
|
rape
|
||||||
|
raped
|
||||||
|
raper
|
||||||
|
rapist
|
||||||
|
raunch
|
||||||
|
rectal
|
||||||
|
rectum
|
||||||
|
rectus
|
||||||
|
reefer
|
||||||
|
reetard
|
||||||
|
reich
|
||||||
|
retard
|
||||||
|
retarded
|
||||||
|
revue
|
||||||
|
rimjob
|
||||||
|
ritard
|
||||||
|
rtard
|
||||||
|
r-tard
|
||||||
|
rum
|
||||||
|
rump
|
||||||
|
rumprammer
|
||||||
|
ruski
|
||||||
|
s.h.i.t.
|
||||||
|
s.o.b.
|
||||||
|
s0b
|
||||||
|
sadism
|
||||||
|
sadist
|
||||||
|
scag
|
||||||
|
scantily
|
||||||
|
schizo
|
||||||
|
schlong
|
||||||
|
screw
|
||||||
|
screwed
|
||||||
|
scrog
|
||||||
|
scrot
|
||||||
|
scrote
|
||||||
|
scrotum
|
||||||
|
scrud
|
||||||
|
scum
|
||||||
|
seaman
|
||||||
|
seamen
|
||||||
|
seduce
|
||||||
|
semen
|
||||||
|
sex
|
||||||
|
sexual
|
||||||
|
sh1t
|
||||||
|
s-h-1-t
|
||||||
|
shamedame
|
||||||
|
shit
|
||||||
|
s-h-i-t
|
||||||
|
shite
|
||||||
|
shiteater
|
||||||
|
shitface
|
||||||
|
shithead
|
||||||
|
shithole
|
||||||
|
shithouse
|
||||||
|
shits
|
||||||
|
shitt
|
||||||
|
shitted
|
||||||
|
shitter
|
||||||
|
shitty
|
||||||
|
shiz
|
||||||
|
sissy
|
||||||
|
skag
|
||||||
|
skank
|
||||||
|
slave
|
||||||
|
sleaze
|
||||||
|
sleazy
|
||||||
|
slut
|
||||||
|
slutdumper
|
||||||
|
slutkiss
|
||||||
|
sluts
|
||||||
|
smegma
|
||||||
|
smut
|
||||||
|
smutty
|
||||||
|
snatch
|
||||||
|
sniper
|
||||||
|
snuff
|
||||||
|
s-o-b
|
||||||
|
sodom
|
||||||
|
souse
|
||||||
|
soused
|
||||||
|
sperm
|
||||||
|
spic
|
||||||
|
spick
|
||||||
|
spik
|
||||||
|
spiks
|
||||||
|
spooge
|
||||||
|
spunk
|
||||||
|
steamy
|
||||||
|
stfu
|
||||||
|
stiffy
|
||||||
|
stoned
|
||||||
|
strip
|
||||||
|
stroke
|
||||||
|
stupid
|
||||||
|
suck
|
||||||
|
sucked
|
||||||
|
sucking
|
||||||
|
sumofabiatch
|
||||||
|
t1t
|
||||||
|
tampon
|
||||||
|
tard
|
||||||
|
tawdry
|
||||||
|
teabagging
|
||||||
|
teat
|
||||||
|
terd
|
||||||
|
teste
|
||||||
|
testee
|
||||||
|
testes
|
||||||
|
testicle
|
||||||
|
testis
|
||||||
|
thrust
|
||||||
|
thug
|
||||||
|
tinkle
|
||||||
|
tit
|
||||||
|
titfuck
|
||||||
|
titi
|
||||||
|
tits
|
||||||
|
tittiefucker
|
||||||
|
titties
|
||||||
|
titty
|
||||||
|
tittyfuck
|
||||||
|
tittyfucker
|
||||||
|
toke
|
||||||
|
toots
|
||||||
|
tramp
|
||||||
|
transsexual
|
||||||
|
trashy
|
||||||
|
tubgirl
|
||||||
|
turd
|
||||||
|
tush
|
||||||
|
twat
|
||||||
|
twats
|
||||||
|
ugly
|
||||||
|
undies
|
||||||
|
unwed
|
||||||
|
urinal
|
||||||
|
urine
|
||||||
|
uterus
|
||||||
|
uzi
|
||||||
|
vag
|
||||||
|
vagina
|
||||||
|
valium
|
||||||
|
viagra
|
||||||
|
virgin
|
||||||
|
vixen
|
||||||
|
vodka
|
||||||
|
vomit
|
||||||
|
voyeur
|
||||||
|
vulgar
|
||||||
|
vulva
|
||||||
|
wad
|
||||||
|
wang
|
||||||
|
wank
|
||||||
|
wanker
|
||||||
|
wazoo
|
||||||
|
wedgie
|
||||||
|
weed
|
||||||
|
weenie
|
||||||
|
weewee
|
||||||
|
weiner
|
||||||
|
weirdo
|
||||||
|
wench
|
||||||
|
wetback
|
||||||
|
wh0re
|
||||||
|
wh0reface
|
||||||
|
whitey
|
||||||
|
whiz
|
||||||
|
whoralicious
|
||||||
|
whore
|
||||||
|
whorealicious
|
||||||
|
whored
|
||||||
|
whoreface
|
||||||
|
whorehopper
|
||||||
|
whorehouse
|
||||||
|
whores
|
||||||
|
whoring
|
||||||
|
wigger
|
||||||
|
womb
|
||||||
|
woody
|
||||||
|
wop
|
||||||
|
wtf
|
||||||
|
x-rated
|
||||||
|
xxx
|
||||||
|
yeasty
|
||||||
|
yobbo
|
||||||
|
zoophile
|
||||||
|
113
code/misc/python/scripts/MITM/app.py
Normal file
113
code/misc/python/scripts/MITM/app.py
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
from flask import Flask, render_template, redirect, url_for, request, flash
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
|
||||||
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
import getpass,datetime
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.secret_key = 'your_secret_key'
|
||||||
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
|
||||||
|
db = SQLAlchemy(app)
|
||||||
|
login_manager = LoginManager()
|
||||||
|
login_manager.init_app(app)
|
||||||
|
login_manager.login_view = 'login'
|
||||||
|
|
||||||
|
class User(UserMixin, db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
username = db.Column(db.String(150), unique=True, nullable=False)
|
||||||
|
password_hash = db.Column(db.String(150), nullable=False)
|
||||||
|
must_change_password = db.Column(db.Boolean, default=True, nullable=False)
|
||||||
|
|
||||||
|
def __init__(self, username, password, must_change_password=True):
|
||||||
|
self.username = username
|
||||||
|
self.password_hash = generate_password_hash(password)
|
||||||
|
self.must_change_password = must_change_password
|
||||||
|
|
||||||
|
def check_password(self, password):
|
||||||
|
return check_password_hash(self.password_hash, password)
|
||||||
|
|
||||||
|
class UserRequest(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
url = db.Column(db.String(500), nullable=False)
|
||||||
|
reason = db.Column(db.String(500), nullable=False)
|
||||||
|
status = db.Column(db.String(50), nullable=False, default='pending')
|
||||||
|
user = db.Column(db.String(150), nullable=False)
|
||||||
|
mac_address = db.Column(db.String(50), nullable=False)
|
||||||
|
ip_address = db.Column(db.String(50), nullable=False)
|
||||||
|
timestamp = db.Column(db.DateTime, nullable=False)
|
||||||
|
|
||||||
|
@login_manager.user_loader
|
||||||
|
def load_user(user_id):
|
||||||
|
return User.query.get(int(user_id))
|
||||||
|
|
||||||
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
|
def login():
|
||||||
|
if request.method == 'POST':
|
||||||
|
username = request.form['username']
|
||||||
|
password = request.form['password']
|
||||||
|
user = User.query.filter_by(username=username).first()
|
||||||
|
if user and user.check_password(password):
|
||||||
|
login_user(user)
|
||||||
|
if user.must_change_password:
|
||||||
|
return redirect(url_for('change_password'))
|
||||||
|
return redirect(url_for('admin'))
|
||||||
|
else:
|
||||||
|
flash('Invalid username or password')
|
||||||
|
return render_template('login.html')
|
||||||
|
|
||||||
|
@app.route('/logout')
|
||||||
|
@login_required
|
||||||
|
def logout():
|
||||||
|
logout_user()
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
|
@app.route('/change_password', methods=['GET', 'POST'])
|
||||||
|
@login_required
|
||||||
|
def change_password():
|
||||||
|
if request.method == 'POST':
|
||||||
|
new_password = request.form['new_password']
|
||||||
|
current_user.password_hash = generate_password_hash(new_password)
|
||||||
|
current_user.must_change_password = False
|
||||||
|
db.session.commit()
|
||||||
|
flash('Password changed successfully')
|
||||||
|
return redirect(url_for('admin'))
|
||||||
|
return render_template('change_password.html')
|
||||||
|
|
||||||
|
@app.route('/admin')
|
||||||
|
@login_required
|
||||||
|
def admin():
|
||||||
|
requests = UserRequest.query.all()
|
||||||
|
return render_template('admin.html', requests=requests)
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template('index.html')
|
||||||
|
|
||||||
|
@app.route('/whitelist', methods=['POST'])
|
||||||
|
def whitelist():
|
||||||
|
url = request.form['url']
|
||||||
|
reason = request.form['reason']
|
||||||
|
user = current_user.username if current_user.is_authenticated else 'anonymous'
|
||||||
|
mac_address = '00:00:00:00:00:00' # Placeholder, replace with actual MAC address retrieval logic
|
||||||
|
ip_address = request.remote_addr # Gets the IP address of the client
|
||||||
|
timestamp = datetime.utcnow()
|
||||||
|
new_request = UserRequest(url=url, reason=reason, user=user, mac_address=mac_address, ip_address=ip_address, timestamp=timestamp)
|
||||||
|
db.session.add(new_request)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
def create_admin_user():
|
||||||
|
admin_user = User.query.filter_by(username='admin').first()
|
||||||
|
if not admin_user:
|
||||||
|
print("No admin user found. Please set a password for the admin user.")
|
||||||
|
password = getpass.getpass("Enter password for admin user: ")
|
||||||
|
admin_user = User(username='admin', password=password)
|
||||||
|
db.session.add(admin_user)
|
||||||
|
db.session.commit()
|
||||||
|
print("Admin user created successfully.")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
with app.app_context():
|
||||||
|
db.create_all()
|
||||||
|
create_admin_user()
|
||||||
|
app.run(debug=True)
|
||||||
133
code/misc/python/scripts/MITM/appv1.py
Normal file
133
code/misc/python/scripts/MITM/appv1.py
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
from flask import Flask, request, render_template, redirect, url_for, session
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from scapy.all import ARP, Ether, srp
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///whitelist.db'
|
||||||
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
|
app.secret_key = 'supersecretkey'
|
||||||
|
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=5)
|
||||||
|
db = SQLAlchemy(app)
|
||||||
|
|
||||||
|
class Whitelist(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
url = db.Column(db.String(255), unique=True, nullable=False)
|
||||||
|
|
||||||
|
class Request(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
url = db.Column(db.String(255), nullable=False)
|
||||||
|
reason = db.Column(db.String(255), nullable=False)
|
||||||
|
status = db.Column(db.String(50), nullable=False, default='pending')
|
||||||
|
timestamp = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
||||||
|
mac_address = db.Column(db.String(17), nullable=False)
|
||||||
|
ip_address = db.Column(db.String(45), nullable=False)
|
||||||
|
|
||||||
|
class Admin(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
password = db.Column(db.String(255), nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_mac_address(ip_address):
|
||||||
|
try:
|
||||||
|
# Create an ARP request packet
|
||||||
|
arp_request = ARP(pdst=ip_address)
|
||||||
|
# Create an Ethernet frame to encapsulate the ARP request
|
||||||
|
ether = Ether(dst="ff:ff:ff:ff:ff:ff")
|
||||||
|
# Combine the Ethernet frame and ARP request
|
||||||
|
packet = ether / arp_request
|
||||||
|
# Send the packet and capture the response
|
||||||
|
result = srp(packet, timeout=3, verbose=False)[0]
|
||||||
|
# Extract the MAC address from the response
|
||||||
|
mac_address = result[0][1].hwsrc
|
||||||
|
return mac_address
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error getting MAC address: {e}")
|
||||||
|
return "00:00:00:00:00:00"
|
||||||
|
|
||||||
|
@app.route('/set_admin_password', methods=['GET', 'POST'])
|
||||||
|
def set_admin_password():
|
||||||
|
if Admin.query.first():
|
||||||
|
return redirect(url_for('admin_login'))
|
||||||
|
if request.method == 'POST':
|
||||||
|
password = request.form['password']
|
||||||
|
hashed_password = generate_password_hash(password)
|
||||||
|
new_admin = Admin(password=hashed_password)
|
||||||
|
db.session.add(new_admin)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for('admin_login'))
|
||||||
|
return render_template('set_admin_password.html')
|
||||||
|
|
||||||
|
@app.route('/admin_login', methods=['GET', 'POST'])
|
||||||
|
def admin_login():
|
||||||
|
if request.method == 'POST':
|
||||||
|
password = request.form['password']
|
||||||
|
admin = Admin.query.first()
|
||||||
|
if admin and check_password_hash(admin.password, password):
|
||||||
|
session['admin_logged_in'] = True
|
||||||
|
session.permanent = True # Mark the session as permanent
|
||||||
|
return redirect(url_for('admin'))
|
||||||
|
else:
|
||||||
|
return "Invalid password"
|
||||||
|
return render_template('admin_login.html')
|
||||||
|
|
||||||
|
@app.route('/admin_logout')
|
||||||
|
def admin_logout():
|
||||||
|
session.pop('admin_logged_in', None)
|
||||||
|
return redirect(url_for('admin_login'))
|
||||||
|
|
||||||
|
@app.route('/admin', methods=['GET', 'POST'])
|
||||||
|
def admin():
|
||||||
|
if not session.get('admin_logged_in'):
|
||||||
|
return redirect(url_for('admin_login'))
|
||||||
|
if request.method == 'POST':
|
||||||
|
action = request.form['action']
|
||||||
|
url = request.form['url']
|
||||||
|
req = Request.query.filter_by(url=url).first()
|
||||||
|
if req:
|
||||||
|
if action == 'approve':
|
||||||
|
req.status = 'approved'
|
||||||
|
if not Whitelist.query.filter_by(url=url).first():
|
||||||
|
new_whitelist = Whitelist(url=url)
|
||||||
|
db.session.add(new_whitelist)
|
||||||
|
elif action == 'reject':
|
||||||
|
req.status = 'rejected'
|
||||||
|
whitelist_entry = Whitelist.query.filter_by(url=url).first()
|
||||||
|
if whitelist_entry:
|
||||||
|
db.session.delete(whitelist_entry)
|
||||||
|
elif action == 'revoke':
|
||||||
|
req.status = 'revoked'
|
||||||
|
whitelist_entry = Whitelist.query.filter_by(url=url).first()
|
||||||
|
if whitelist_entry:
|
||||||
|
db.session.delete(whitelist_entry)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for('admin'))
|
||||||
|
requests = Request.query.all()
|
||||||
|
whitelist = Whitelist.query.all()
|
||||||
|
return render_template('admin.html', requests=requests, whitelist=whitelist)
|
||||||
|
|
||||||
|
@app.route('/whitelist', methods=['GET'])
|
||||||
|
def get_whitelist():
|
||||||
|
whitelist = Whitelist.query.all()
|
||||||
|
return {"whitelist": [entry.url for entry in whitelist]}
|
||||||
|
|
||||||
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
|
def request_whitelist():
|
||||||
|
if request.method == 'POST':
|
||||||
|
url = request.form['url']
|
||||||
|
reason = request.form['reason']
|
||||||
|
ip_address = request.remote_addr
|
||||||
|
mac_address = get_mac_address(ip_address)
|
||||||
|
new_request = Request(url=url, reason=reason, mac_address=mac_address, ip_address=ip_address)
|
||||||
|
db.session.add(new_request)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for('request_whitelist'))
|
||||||
|
return render_template('request.html')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
with app.app_context():
|
||||||
|
db.create_all()
|
||||||
|
|
||||||
|
app.run(debug=True)
|
||||||
209
code/misc/python/scripts/MITM/driver.py
Normal file
209
code/misc/python/scripts/MITM/driver.py
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
import asyncio
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
import zlib
|
||||||
|
import json
|
||||||
|
import csv
|
||||||
|
import requests
|
||||||
|
from mitmproxy import http, ctx
|
||||||
|
from mitmproxy import options
|
||||||
|
from mitmproxy.tools import dump
|
||||||
|
import sqlite3
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
# Method 1: Load blocked words from a CSV file
|
||||||
|
def load_blocked_words_from_csv(file_path):
|
||||||
|
"""
|
||||||
|
Loads blocked words from a CSV file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
file_path (str): The path to the CSV file containing blocked words.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: A list of blocked words loaded from the CSV file.
|
||||||
|
"""
|
||||||
|
blocked_words = []
|
||||||
|
with open(file_path, newline='') as csvfile:
|
||||||
|
reader = csv.reader(csvfile)
|
||||||
|
for row in reader:
|
||||||
|
blocked_words.extend(row)
|
||||||
|
return blocked_words
|
||||||
|
|
||||||
|
# Method 2: Load blocked words from a web service
|
||||||
|
def load_blocked_words_from_web_service(url):
|
||||||
|
"""
|
||||||
|
Fetches blocked words from a web service.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url (str): The URL of the web service to fetch blocked words from.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: A list of blocked words.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
response = requests.get(url)
|
||||||
|
response.raise_for_status() # Raise an error for bad status codes
|
||||||
|
blocked_words = response.json() # Assuming the response is a JSON array of words
|
||||||
|
return blocked_words
|
||||||
|
except requests.RequestException as e:
|
||||||
|
ctx.log.error(f"Error fetching blocked words: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
# Load blocked words from the web service
|
||||||
|
blocked_words = ['fdhfghrth']#load_blocked_words_from_csv('Terms-to-Block.csv')
|
||||||
|
#blocked_words = load_blocked_words_from_web_service('https://example.com/api/blocked_words')
|
||||||
|
|
||||||
|
# Compile a regex pattern for blocked words
|
||||||
|
pattern = re.compile(r'\b(?:' + '|'.join(re.escape(word) for word in blocked_words) + r')\b', re.IGNORECASE)
|
||||||
|
|
||||||
|
def check_string_in_list(target_string, string_list):
|
||||||
|
"""
|
||||||
|
Checks if any string in a list is present in the target string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
target_string (str): The string to search within.
|
||||||
|
string_list (list): The list of strings to search for.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if any string in the list is found in the target string, False otherwise.
|
||||||
|
"""
|
||||||
|
return any(item in target_string for item in string_list)
|
||||||
|
|
||||||
|
def search_blocked_words_in_json(data, pattern):
|
||||||
|
"""
|
||||||
|
Recursively searches for blocked words in a JSON object.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
data (dict or list or str): The JSON data to search within.
|
||||||
|
pattern (re.Pattern): The compiled regex pattern for blocked words.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: A list of matches found in the JSON data.
|
||||||
|
"""
|
||||||
|
matches = []
|
||||||
|
if isinstance(data, dict):
|
||||||
|
for key, value in data.items():
|
||||||
|
matches.extend(search_blocked_words_in_json(value, pattern))
|
||||||
|
elif isinstance(data, list):
|
||||||
|
for item in data:
|
||||||
|
matches.extend(search_blocked_words_in_json(item, pattern))
|
||||||
|
elif isinstance(data, str):
|
||||||
|
matches.extend(pattern.findall(data))
|
||||||
|
return matches
|
||||||
|
|
||||||
|
class RequestLogger:
|
||||||
|
"""
|
||||||
|
A class to log and filter HTTP requests and responses.
|
||||||
|
"""
|
||||||
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Initializes the RequestLogger and loads the whitelist.
|
||||||
|
"""
|
||||||
|
self.whitelist = []
|
||||||
|
asyncio.create_task(self.load_whitelist_periodically())
|
||||||
|
|
||||||
|
async def load_whitelist(self):
|
||||||
|
"""
|
||||||
|
Loads the whitelist from the SQLite database.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: A list of whitelisted URLs.
|
||||||
|
"""
|
||||||
|
conn = sqlite3.connect('whitelist.db')
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT url FROM whitelist WHERE status='approved'")
|
||||||
|
self.whitelist = [row[0] for row in c.fetchall()]
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
async def load_whitelist_periodically(self):
|
||||||
|
"""
|
||||||
|
Periodically loads the whitelist every 20 seconds.
|
||||||
|
"""
|
||||||
|
while True:
|
||||||
|
await self.load_whitelist()
|
||||||
|
await asyncio.sleep(20)
|
||||||
|
|
||||||
|
def request(self, flow: http.HTTPFlow):
|
||||||
|
"""
|
||||||
|
Handles HTTP requests. Blocks requests to non-whitelisted URLs.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
flow (http.HTTPFlow): The HTTP flow object.
|
||||||
|
"""
|
||||||
|
if flow.request.pretty_host not in self.whitelist:
|
||||||
|
ctx.log.info('Blocked request to %s' % flow.request.host)
|
||||||
|
flow.response = http.Response.make(
|
||||||
|
403, # Forbidden status code
|
||||||
|
b"Blocked by URL whitelist", # Response content
|
||||||
|
{"Content-Type": "text/plain"} # Response headers
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
def response(self, flow: http.HTTPFlow):
|
||||||
|
"""
|
||||||
|
Handles HTTP responses. Searches for blocked words in the response content.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
flow (http.HTTPFlow): The HTTP flow object.
|
||||||
|
"""
|
||||||
|
content_type = flow.response.headers.get("Content-Type", "")
|
||||||
|
content = flow.response.content
|
||||||
|
|
||||||
|
# Handle compressed content
|
||||||
|
if "gzip" in flow.response.headers.get("Content-Encoding", ""):
|
||||||
|
content = zlib.decompress(content, zlib.MAX_WBITS | 16)
|
||||||
|
|
||||||
|
if "deflate" in flow.response.headers.get("Content-Encoding", ""):
|
||||||
|
content = zlib.decompress(content)
|
||||||
|
|
||||||
|
# Decode content to text
|
||||||
|
if isinstance(content, bytes):
|
||||||
|
content = content.decode('utf-8', errors='ignore')
|
||||||
|
|
||||||
|
# Check if content is HTML
|
||||||
|
if "text/html" in content_type:
|
||||||
|
soup = BeautifulSoup(content, 'html.parser')
|
||||||
|
text = soup.get_text()
|
||||||
|
matches = pattern.findall(text)
|
||||||
|
elif "application/json" in content_type:
|
||||||
|
data = json.loads(content)
|
||||||
|
matches = search_blocked_words_in_json(data, pattern)
|
||||||
|
else:
|
||||||
|
matches = []
|
||||||
|
|
||||||
|
# Search for matches in the text content
|
||||||
|
if matches:
|
||||||
|
matched_keyword = matches[0]
|
||||||
|
flow.response.text = 'response contains filtered contents'
|
||||||
|
ctx.log.error(matched_keyword)
|
||||||
|
|
||||||
|
flow.response = http.Response.make(
|
||||||
|
200, # (optional) status code
|
||||||
|
b"Hello World", # (optional) content
|
||||||
|
{"Content-Type": "text/html"}, # (optional) headers
|
||||||
|
)
|
||||||
|
|
||||||
|
async def start_proxy(host, port):
|
||||||
|
"""
|
||||||
|
Starts the proxy server.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
host (str): The host address to listen on.
|
||||||
|
port (int): The port to listen on.
|
||||||
|
"""
|
||||||
|
opts = options.Options(listen_host=host, listen_port=port)
|
||||||
|
|
||||||
|
master = dump.DumpMaster(
|
||||||
|
opts,
|
||||||
|
with_termlog=False,
|
||||||
|
with_dumper=False,
|
||||||
|
)
|
||||||
|
master.addons.add(RequestLogger())
|
||||||
|
|
||||||
|
await master.run()
|
||||||
|
return master
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
host = sys.argv[1]
|
||||||
|
port = int(sys.argv[2])
|
||||||
|
asyncio.run(start_proxy(host, port))
|
||||||
9
code/misc/python/scripts/MITM/myaddon.py
Normal file
9
code/misc/python/scripts/MITM/myaddon.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import mitmproxy.http
|
||||||
|
|
||||||
|
class MyAddon:
|
||||||
|
def request(self, flow: mitmproxy.http.HTTPFlow) -> None:
|
||||||
|
print(flow.request.url)
|
||||||
|
|
||||||
|
addons = [
|
||||||
|
MyAddon()
|
||||||
|
]
|
||||||
67
code/misc/python/scripts/MITM/templates/admin.html
Normal file
67
code/misc/python/scripts/MITM/templates/admin.html
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Admin Dashboard</title>
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="mt-5">Admin Dashboard</h1>
|
||||||
|
<a href="{{ url_for('admin_logout') }}" class="btn btn-danger float-right">Logout</a>
|
||||||
|
<h2 class="mt-4">Pending Requests</h2>
|
||||||
|
<table class="table table-bordered mt-3">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>URL/Domain</th>
|
||||||
|
<th>Reason</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Date & Time</th>
|
||||||
|
<th>IP Address</th>
|
||||||
|
<th>MAC Address</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for req in requests %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ req.url }}</td>
|
||||||
|
<td>{{ req.reason }}</td>
|
||||||
|
<td>{{ req.status }}</td>
|
||||||
|
<td>{{ req.timestamp }}</td>
|
||||||
|
<td>{{ req.ip_address }}</td>
|
||||||
|
<td>{{ req.mac_address }}</td>
|
||||||
|
<td>
|
||||||
|
<form method="post" class="d-inline">
|
||||||
|
<input type="hidden" name="url" value="{{ req.url }}">
|
||||||
|
<input type="hidden" name="action" value="approve">
|
||||||
|
<button type="submit" class="btn btn-success btn-sm">Approve</button>
|
||||||
|
</form>
|
||||||
|
<form method="post" class="d-inline">
|
||||||
|
<input type="hidden" name="url" value="{{ req.url }}">
|
||||||
|
<input type="hidden" name="action" value="reject">
|
||||||
|
<button type="submit" class="btn btn-danger btn-sm">Reject</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<h2 class="mt-4">Whitelisted URLs/Domains</h2>
|
||||||
|
<ul class="list-group mt-3">
|
||||||
|
{% for url in whitelist %}
|
||||||
|
<li class="list-group-item">
|
||||||
|
{{ url.url }}
|
||||||
|
<form method="post" class="d-inline float-right">
|
||||||
|
<input type="hidden" name="url" value="{{ url.url }}">
|
||||||
|
<input type="hidden" name="action" value="revoke">
|
||||||
|
<button type="submit" class="btn btn-warning btn-sm">Revoke</button>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
|
||||||
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
22
code/misc/python/scripts/MITM/templates/admin_login.html
Normal file
22
code/misc/python/scripts/MITM/templates/admin_login.html
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Admin Login</title>
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="mt-5">Admin Login</h1>
|
||||||
|
<form method="post" class="mt-3">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Login</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
|
||||||
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
15
code/misc/python/scripts/MITM/templates/change_password.html
Normal file
15
code/misc/python/scripts/MITM/templates/change_password.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Change Password</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Change Password</h1>
|
||||||
|
<form method="POST">
|
||||||
|
<label for="new_password">New Password:</label>
|
||||||
|
<input type="password" name="new_password" id="new_password" required>
|
||||||
|
<br>
|
||||||
|
<button type="submit">Change Password</button>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
23
code/misc/python/scripts/MITM/templates/index.html
Normal file
23
code/misc/python/scripts/MITM/templates/index.html
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Whitelist Request</title>
|
||||||
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container mt-5">
|
||||||
|
<h1 class="mb-4">Request to Whitelist a URL</h1>
|
||||||
|
<form action="/whitelist" method="post">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="url">URL:</label>
|
||||||
|
<input type="text" class="form-control" id="url" name="url" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="reason">Reason:</label>
|
||||||
|
<textarea class="form-control" id="reason" name="reason" rows="3" required></textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
27
code/misc/python/scripts/MITM/templates/login.html
Normal file
27
code/misc/python/scripts/MITM/templates/login.html
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Login</h1>
|
||||||
|
<form method="POST">
|
||||||
|
<label for="username">Username:</label>
|
||||||
|
<input type="text" name="username" id="username" required>
|
||||||
|
<br>
|
||||||
|
<label for="password">Password:</label>
|
||||||
|
<input type="password" name="password" id="password" required>
|
||||||
|
<br>
|
||||||
|
<button type="submit">Login</button>
|
||||||
|
</form>
|
||||||
|
{% with messages = get_flashed_messages() %}
|
||||||
|
{% if messages %}
|
||||||
|
<ul>
|
||||||
|
{% for message in messages %}
|
||||||
|
<li>{{ message }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
26
code/misc/python/scripts/MITM/templates/request.html
Normal file
26
code/misc/python/scripts/MITM/templates/request.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Request Whitelist</title>
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="mt-5">Request URL/Domain Whitelisting</h1>
|
||||||
|
<form method="post" class="mt-3">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="url">URL/Domain</label>
|
||||||
|
<input type="text" class="form-control" id="url" name="url" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="reason">Reason</label>
|
||||||
|
<input type="text" class="form-control" id="reason" name="reason" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
|
||||||
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Set Admin Password</title>
|
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="mt-5">Set Admin Password</h1>
|
||||||
|
<form method="post" class="mt-3">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Set Password</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
|
||||||
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
27
code/misc/python/scripts/MITM/templates/whitelist.html
Normal file
27
code/misc/python/scripts/MITM/templates/whitelist.html
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Whitelisted URLs</title>
|
||||||
|
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container mt-5">
|
||||||
|
<h1 class="mb-4">Whitelisted URLs</h1>
|
||||||
|
<a href="{{ url_for('admin') }}" class="btn btn-secondary mb-4">Back to Admin</a>
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead class="thead-dark">
|
||||||
|
<tr>
|
||||||
|
<th>URL</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for url in approved_urls %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ url[0] }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
73
code/misc/python/scripts/MITM/testwflow.ipynb
Normal file
73
code/misc/python/scripts/MITM/testwflow.ipynb
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Error logged during startup, exiting...\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ename": "SystemExit",
|
||||||
|
"evalue": "1",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"An exception has occurred, use %tb to see the full traceback.\n",
|
||||||
|
"\u001b[0;31mSystemExit\u001b[0m\u001b[0;31m:\u001b[0m 1\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"/home/ys/.pyenv/versions/3.12.0/envs/mitm/lib/python3.12/site-packages/IPython/core/interactiveshell.py:3585: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n",
|
||||||
|
" warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import driver\n",
|
||||||
|
"import asyncio\n",
|
||||||
|
"import nest_asyncio\n",
|
||||||
|
"\n",
|
||||||
|
"# Apply nest_asyncio to allow nested event loops\n",
|
||||||
|
"#nest_asyncio.apply()\n",
|
||||||
|
"\n",
|
||||||
|
"await driver.start_proxy('127.0.0.1', 8083)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "mitm",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.12.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
1250
code/misc/python/scripts/SIMM Gamma check.ipynb
Normal file
1250
code/misc/python/scripts/SIMM Gamma check.ipynb
Normal file
File diff suppressed because one or more lines are too long
215
code/misc/python/scripts/Untitled1.ipynb
Normal file
215
code/misc/python/scripts/Untitled1.ipynb
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import numpy as np\n",
|
||||||
|
"\n",
|
||||||
|
"from pylatex import Document, Section, Subsection, Math, Matrix, VectorName\n",
|
||||||
|
"\n",
|
||||||
|
"if __name__ == '__main__':\n",
|
||||||
|
" a = np.array([[100, 10, 20]]).T\n",
|
||||||
|
"\n",
|
||||||
|
" doc = Document()\n",
|
||||||
|
" section = Section('Numpy tests')\n",
|
||||||
|
" subsection = Subsection('Array')\n",
|
||||||
|
"\n",
|
||||||
|
" vec = Matrix(a)\n",
|
||||||
|
" vec_name = VectorName('a')\n",
|
||||||
|
" math = Math(data=[vec_name, '=', vec])\n",
|
||||||
|
"\n",
|
||||||
|
" subsection.append(math)\n",
|
||||||
|
" section.append(subsection)\n",
|
||||||
|
"\n",
|
||||||
|
" subsection = Subsection('Matrix')\n",
|
||||||
|
" M = np.matrix([[2, 3, 4],\n",
|
||||||
|
" [0, 0, 1],\n",
|
||||||
|
" [0, 0, 2]])\n",
|
||||||
|
" matrix = Matrix(M, mtype='b')\n",
|
||||||
|
" math = Math(data=['M=', matrix])\n",
|
||||||
|
"\n",
|
||||||
|
" subsection.append(math)\n",
|
||||||
|
" section.append(subsection)\n",
|
||||||
|
"\n",
|
||||||
|
" subsection = Subsection('Product')\n",
|
||||||
|
"\n",
|
||||||
|
" math = Math(data=['M', vec_name, '=', Matrix(M * a)])\n",
|
||||||
|
" subsection.append(math)\n",
|
||||||
|
"\n",
|
||||||
|
" section.append(subsection)\n",
|
||||||
|
"\n",
|
||||||
|
" doc.append(section)\n",
|
||||||
|
" doc.generate_pdf('numpy_ex', clean_tex=False)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"/home/ys/.pyenv/versions/3.12.0/bin/pip\n",
|
||||||
|
"asttokens==3.0.0\n",
|
||||||
|
"comm==0.2.2\n",
|
||||||
|
"debugpy==1.8.9\n",
|
||||||
|
"decorator==5.1.1\n",
|
||||||
|
"executing==2.1.0\n",
|
||||||
|
"ipykernel==6.29.5\n",
|
||||||
|
"ipython==8.30.0\n",
|
||||||
|
"jax==0.4.35\n",
|
||||||
|
"jax-cuda12-pjrt==0.4.35\n",
|
||||||
|
"jax-cuda12-plugin==0.4.35\n",
|
||||||
|
"jaxlib==0.4.34\n",
|
||||||
|
"jedi==0.19.2\n",
|
||||||
|
"jupyter_client==8.6.3\n",
|
||||||
|
"jupyter_core==5.7.2\n",
|
||||||
|
"matplotlib-inline==0.1.7\n",
|
||||||
|
"ml_dtypes==0.5.0\n",
|
||||||
|
"nest-asyncio==1.6.0\n",
|
||||||
|
"numpy==2.1.3\n",
|
||||||
|
"nvidia-cublas-cu12==12.6.4.1\n",
|
||||||
|
"nvidia-cuda-cupti-cu12==12.6.80\n",
|
||||||
|
"nvidia-cuda-nvcc-cu12==12.6.85\n",
|
||||||
|
"nvidia-cuda-runtime-cu12==12.6.77\n",
|
||||||
|
"nvidia-cudnn-cu12==9.5.1.17\n",
|
||||||
|
"nvidia-cufft-cu12==11.3.0.4\n",
|
||||||
|
"nvidia-cusolver-cu12==11.7.1.2\n",
|
||||||
|
"nvidia-cusparse-cu12==12.5.4.2\n",
|
||||||
|
"nvidia-nccl-cu12==2.23.4\n",
|
||||||
|
"nvidia-nvjitlink-cu12==12.6.85\n",
|
||||||
|
"opt_einsum==3.4.0\n",
|
||||||
|
"packaging==24.2\n",
|
||||||
|
"parso==0.8.4\n",
|
||||||
|
"pexpect==4.9.0\n",
|
||||||
|
"platformdirs==4.3.6\n",
|
||||||
|
"prompt_toolkit==3.0.48\n",
|
||||||
|
"psutil==6.1.0\n",
|
||||||
|
"ptyprocess==0.7.0\n",
|
||||||
|
"pure_eval==0.2.3\n",
|
||||||
|
"Pygments==2.18.0\n",
|
||||||
|
"python-dateutil==2.9.0.post0\n",
|
||||||
|
"pyzmq==26.2.0\n",
|
||||||
|
"scipy==1.14.1\n",
|
||||||
|
"six==1.16.0\n",
|
||||||
|
"stack-data==0.6.3\n",
|
||||||
|
"tornado==6.4.2\n",
|
||||||
|
"traitlets==5.14.3\n",
|
||||||
|
"wcwidth==0.2.13\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"!pyenv which pip\n",
|
||||||
|
"!pip freeze\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"True"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import jax\n",
|
||||||
|
"import jax.numpy as jnp\n",
|
||||||
|
"\n",
|
||||||
|
"x = jnp.arange(5)\n",
|
||||||
|
"isinstance(x, jax.Array)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"{CpuDevice(id=0)}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"x.devices()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"[0. 1.05 2.1 3.1499999 4.2 ]\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import jax.numpy as jnp\n",
|
||||||
|
"def selu(x, alpha=1.67, lmbda=1.05):\n",
|
||||||
|
" return lmbda * jnp.where(x > 0, x, alpha * jnp.exp(x) - alpha)\n",
|
||||||
|
"\n",
|
||||||
|
"x = jnp.arange(5.0)\n",
|
||||||
|
"print(selu(x))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.12.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
|
}
|
||||||
1031
code/misc/python/scripts/audioconversion.html
Normal file
1031
code/misc/python/scripts/audioconversion.html
Normal file
File diff suppressed because it is too large
Load Diff
526
code/misc/python/scripts/code snippets.ipynb
Normal file
526
code/misc/python/scripts/code snippets.ipynb
Normal file
@@ -0,0 +1,526 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import random\n",
|
||||||
|
"import string\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"import numpy as np\n",
|
||||||
|
"random.seed(34)\n",
|
||||||
|
"%load_ext autotime\n",
|
||||||
|
"def randomStringDigits(stringLength=12):\n",
|
||||||
|
" \"\"\"Generate a random string of letters and digits \"\"\"\n",
|
||||||
|
" lettersAndDigits = string.ascii_uppercase + string.digits\n",
|
||||||
|
" return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 208,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"time: 90.8 ms\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"NUMSTR=10000\n",
|
||||||
|
"tkrs=np.array([randomStringDigits() for x in np.arange(1,NUMSTR)])\n",
|
||||||
|
"brokentkrs=np.array([i[2:-1] for i in tkrs])\n",
|
||||||
|
"tkrs;\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 209,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"time: 507 µs\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"brokentkrs;"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 210,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"time: 58.5 ms\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"\n",
|
||||||
|
"#now shuffle!\n",
|
||||||
|
"random.shuffle(tkrs)\n",
|
||||||
|
"random.shuffle(tkrs)\n",
|
||||||
|
"random.shuffle(brokentkrs)\n",
|
||||||
|
"random.shuffle(brokentkrs)\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 214,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"time: 7.91 ms\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"masks=dict(zip(tkrs,np.ones(tkrs.size,dtype=bool)))\n",
|
||||||
|
"def simplematch(tkrtofind):\n",
|
||||||
|
" res=''\n",
|
||||||
|
" maskedtkrs=tkrs[list(masks.values())]\n",
|
||||||
|
" mask=np.char.find(maskedtkrs,tkrtofind)\n",
|
||||||
|
" loc=np.where(mask>=0)\n",
|
||||||
|
" \n",
|
||||||
|
" #print (len(masks),len(tkrs[masks]),loc[0])\n",
|
||||||
|
" \n",
|
||||||
|
" if loc[0].size>0:\n",
|
||||||
|
" res=maskedtkrs[loc[0][0]]\n",
|
||||||
|
" masks[res]=False\n",
|
||||||
|
" else:\n",
|
||||||
|
" res='nan' \n",
|
||||||
|
" \n",
|
||||||
|
" return res"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 215,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"time: 34.3 s\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"res={i:simplematch(i) for i in brokentkrs}\n",
|
||||||
|
"res;"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 213,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"{'DO71TDBQA': 'AXDO71TDBQAM',\n",
|
||||||
|
" 'JDA55EFIE': '3MJDA55EFIEV',\n",
|
||||||
|
" '6QMMGHNHJ': '4F6QMMGHNHJD',\n",
|
||||||
|
" '9TWGE0QES': 'FR9TWGE0QESJ',\n",
|
||||||
|
" '45AU9WLCH': 'KF45AU9WLCHF',\n",
|
||||||
|
" 'CSYWNFXTY': '34CSYWNFXTY8',\n",
|
||||||
|
" 'TWNKEAA82': '25TWNKEAA82P',\n",
|
||||||
|
" 'UW3JOMUTJ': 'L2UW3JOMUTJ4',\n",
|
||||||
|
" '5B3ANSSUZ': 'WU5B3ANSSUZX',\n",
|
||||||
|
" 'TGUCHCYND': '0ATGUCHCYNDE',\n",
|
||||||
|
" 'CXV9QVJ9Z': 'W8CXV9QVJ9ZY',\n",
|
||||||
|
" 'OMET7YX51': 'J7OMET7YX511',\n",
|
||||||
|
" '5H0AUF5O8': 'Y85H0AUF5O80',\n",
|
||||||
|
" '4NA1X7RIQ': 'TO4NA1X7RIQ0',\n",
|
||||||
|
" '7VWM39ZEV': 'MZ7VWM39ZEVG',\n",
|
||||||
|
" 'RA86HZ3R3': 'EJRA86HZ3R3Q',\n",
|
||||||
|
" 'E58UP20DN': '9KE58UP20DN5',\n",
|
||||||
|
" 'DRIGFBUDU': 'JMDRIGFBUDU8',\n",
|
||||||
|
" 'QGTVH08TY': 'X9QGTVH08TYQ',\n",
|
||||||
|
" 'TB5HBIXX5': 'MNTB5HBIXX5Z',\n",
|
||||||
|
" 'UB7RL30VX': '8AUB7RL30VXJ',\n",
|
||||||
|
" 'YD22RW7IL': '0JYD22RW7IL3',\n",
|
||||||
|
" 'ONTVH3717': 'DRONTVH3717G',\n",
|
||||||
|
" 'NQ7LJ1X88': 'HINQ7LJ1X886',\n",
|
||||||
|
" 'KQBDT60Y8': 'W9KQBDT60Y87',\n",
|
||||||
|
" '36LUE20GT': 'Z236LUE20GT5',\n",
|
||||||
|
" '99D1HYQ0J': 'GA99D1HYQ0JZ',\n",
|
||||||
|
" '66CHBXYDA': '1U66CHBXYDA6',\n",
|
||||||
|
" 'LJR0XO7V0': 'KWLJR0XO7V0U',\n",
|
||||||
|
" 'EE259D0EG': '2BEE259D0EGK',\n",
|
||||||
|
" 'KFY2QYCM4': '56KFY2QYCM42',\n",
|
||||||
|
" 'IBSXMP0HC': 'OSIBSXMP0HCT',\n",
|
||||||
|
" 'P3FFUFE05': 'M0P3FFUFE052',\n",
|
||||||
|
" 'HAMR3Z96M': 'XSHAMR3Z96MC',\n",
|
||||||
|
" 'I2WWAOZG7': 'D3I2WWAOZG7C',\n",
|
||||||
|
" 'X9HLCJHAP': '7LX9HLCJHAP6',\n",
|
||||||
|
" 'QS1N6LGIJ': 'AVQS1N6LGIJK',\n",
|
||||||
|
" 'IDIEFIRTV': 'TXIDIEFIRTV5',\n",
|
||||||
|
" '9HFVGP9S8': 'NW9HFVGP9S8T',\n",
|
||||||
|
" 'BXZ4UJU17': 'TPBXZ4UJU17P',\n",
|
||||||
|
" '0DA0OOTM3': 'AB0DA0OOTM3V',\n",
|
||||||
|
" '1TU3V5YG5': 'DI1TU3V5YG5L',\n",
|
||||||
|
" 'KQCDAZVF5': 'I9KQCDAZVF5K',\n",
|
||||||
|
" 'ADRZ64V1A': '6GADRZ64V1AI',\n",
|
||||||
|
" 'D0Z5UPPPO': '9FD0Z5UPPPOJ',\n",
|
||||||
|
" '9B945PL1J': 'H19B945PL1JS',\n",
|
||||||
|
" '5YMO22TFS': 'ZI5YMO22TFS9',\n",
|
||||||
|
" 'CARTXHPPM': '0MCARTXHPPMG',\n",
|
||||||
|
" '8VHPC64KM': 'DM8VHPC64KMR',\n",
|
||||||
|
" 'PB00TLGNR': 'GQPB00TLGNRS',\n",
|
||||||
|
" 'X6YV0CTST': 'MGX6YV0CTST4',\n",
|
||||||
|
" '9PR47TAGG': 'FX9PR47TAGGP',\n",
|
||||||
|
" 'WPBHE899U': '8LWPBHE899UA',\n",
|
||||||
|
" 'MZPMCLYMC': 'TJMZPMCLYMCY',\n",
|
||||||
|
" '1A2D2BKHO': '181A2D2BKHOG',\n",
|
||||||
|
" 'N5RP7GSIM': '3WN5RP7GSIM3',\n",
|
||||||
|
" '5PIAOWPNB': '7H5PIAOWPNB3',\n",
|
||||||
|
" 'NQO5KRURM': 'VRNQO5KRURMZ',\n",
|
||||||
|
" 'GKE8QCZEB': 'G1GKE8QCZEBO',\n",
|
||||||
|
" 'X166UN51M': '65X166UN51ML',\n",
|
||||||
|
" 'ZBCBFQTJA': '1KZBCBFQTJA7',\n",
|
||||||
|
" '4MMEOSTLY': 'W44MMEOSTLY7',\n",
|
||||||
|
" 'FA2B94LAY': '55FA2B94LAYZ',\n",
|
||||||
|
" 'HO72ENGP7': 'ZEHO72ENGP79',\n",
|
||||||
|
" 'HLTT2SPHG': '9THLTT2SPHG3',\n",
|
||||||
|
" 'ES2KN7J5A': 'CQES2KN7J5A7',\n",
|
||||||
|
" 'RWGWKUE3H': '8TRWGWKUE3HC',\n",
|
||||||
|
" 'DELUHV2VP': 'A5DELUHV2VPW',\n",
|
||||||
|
" 'SCTTTONHR': 'KLSCTTTONHRI',\n",
|
||||||
|
" 'FH33UVR73': 'M0FH33UVR73A',\n",
|
||||||
|
" 'XHVE98LH5': '6QXHVE98LH57',\n",
|
||||||
|
" '8YM64AWEQ': 'HT8YM64AWEQ5',\n",
|
||||||
|
" 'IIDS6JXSZ': 'SVIIDS6JXSZG',\n",
|
||||||
|
" '91NGKTSD1': 'ZB91NGKTSD15',\n",
|
||||||
|
" 'V89EIY5OM': 'W0V89EIY5OM3',\n",
|
||||||
|
" 'KKK6O3LKR': 'Y1KKK6O3LKR3',\n",
|
||||||
|
" 'KLQ03Y1ZT': 'S7KLQ03Y1ZT3',\n",
|
||||||
|
" 'CWCZKK9Y7': 'G5CWCZKK9Y7Q',\n",
|
||||||
|
" 'VE2OZJZF5': '1BVE2OZJZF59',\n",
|
||||||
|
" 'W8XP182B5': 'M5W8XP182B53',\n",
|
||||||
|
" '6GD1A8LHD': '696GD1A8LHDI',\n",
|
||||||
|
" '8MO8Y1ES0': 'RN8MO8Y1ES0K',\n",
|
||||||
|
" 'T1ZBGJHVM': 'BYT1ZBGJHVMG',\n",
|
||||||
|
" 'M5HR5ZQIY': 'BLM5HR5ZQIYR',\n",
|
||||||
|
" '4XLFJ05JG': 'F34XLFJ05JGS',\n",
|
||||||
|
" 'YFP72SLK7': 'Z7YFP72SLK7N',\n",
|
||||||
|
" 'ES0JIOPJ2': 'OZES0JIOPJ2K',\n",
|
||||||
|
" 'KV3CFMYRM': 'EFKV3CFMYRMW',\n",
|
||||||
|
" '9AEUN9UCH': 'QZ9AEUN9UCH8',\n",
|
||||||
|
" 'LURZ8V5E1': 'E2LURZ8V5E13',\n",
|
||||||
|
" 'WF4VPFQTR': 'YWWF4VPFQTRH',\n",
|
||||||
|
" 'UCNZXFSRY': '5XUCNZXFSRY7',\n",
|
||||||
|
" 'RC6RTNLKL': 'YXRC6RTNLKLG',\n",
|
||||||
|
" 'XOE94B8C5': 'XNXOE94B8C58',\n",
|
||||||
|
" '601CLQTOB': 'DP601CLQTOB6',\n",
|
||||||
|
" 'VNDIXZ7JW': 'ZUVNDIXZ7JWG',\n",
|
||||||
|
" 'MQES3LJA6': 'MKMQES3LJA6Q',\n",
|
||||||
|
" 'GBF82ZK6I': 'X9GBF82ZK6IH',\n",
|
||||||
|
" 'S3C1SYRM7': 'HPS3C1SYRM7P',\n",
|
||||||
|
" 'DEXTKGLC0': 'R0DEXTKGLC0W',\n",
|
||||||
|
" 'M0U7OH207': 'U8M0U7OH207A',\n",
|
||||||
|
" '3ZG6HVKOM': 'A63ZG6HVKOM5',\n",
|
||||||
|
" 'A22JVYIXB': '50A22JVYIXBT',\n",
|
||||||
|
" 'ZG5MZ9ULG': 'J3ZG5MZ9ULG0',\n",
|
||||||
|
" 'T53ARN9U6': 'PHT53ARN9U6P',\n",
|
||||||
|
" 'M99IBS4BA': '48M99IBS4BAV',\n",
|
||||||
|
" 'E3CCA3XPJ': 'IKE3CCA3XPJF',\n",
|
||||||
|
" '2RQO0REPB': 'X52RQO0REPBV',\n",
|
||||||
|
" 'BYJHZLAFC': '24BYJHZLAFC1',\n",
|
||||||
|
" 'BTWDT1YIC': '3NBTWDT1YIC2',\n",
|
||||||
|
" 'TTCQT8FAD': '69TTCQT8FADJ',\n",
|
||||||
|
" 'W1I292YWM': '87W1I292YWMT',\n",
|
||||||
|
" '3VN0549AR': 'HP3VN0549ARZ',\n",
|
||||||
|
" 'I1ITMX68K': 'Y8I1ITMX68KZ',\n",
|
||||||
|
" 'F6OHHSGMN': 'XBF6OHHSGMNX',\n",
|
||||||
|
" 'DHKU2MCFV': 'HADHKU2MCFVG',\n",
|
||||||
|
" 'ZQIQBQ4HB': 'LVZQIQBQ4HBP',\n",
|
||||||
|
" '7UDGVRNQH': 'AB7UDGVRNQHF',\n",
|
||||||
|
" '8ISWSJZRE': 'IW8ISWSJZREL',\n",
|
||||||
|
" 'D443SKQV9': 'MFD443SKQV95',\n",
|
||||||
|
" '4NPV5ILXW': 'BR4NPV5ILXWX',\n",
|
||||||
|
" 'YUMPHU8KH': 'O2YUMPHU8KHW',\n",
|
||||||
|
" 'CUU6WOLK9': 'QJCUU6WOLK94',\n",
|
||||||
|
" 'TZQTGORKP': 'WOTZQTGORKP0',\n",
|
||||||
|
" '1HURTWU07': '3Q1HURTWU07A',\n",
|
||||||
|
" 'GE57S1K5Y': 'CDGE57S1K5Y8',\n",
|
||||||
|
" '6R46YLDI9': 'D96R46YLDI9S',\n",
|
||||||
|
" '4917064S4': 'UX4917064S4M',\n",
|
||||||
|
" 'KK5LDDSZA': 'RMKK5LDDSZA7',\n",
|
||||||
|
" 'NO5NV97AF': '42NO5NV97AFF',\n",
|
||||||
|
" 'VGCV7JV7L': '87VGCV7JV7LO',\n",
|
||||||
|
" 'R4T1LKGDY': 'IAR4T1LKGDYD',\n",
|
||||||
|
" 'HAWV27DB7': 'DNHAWV27DB7V',\n",
|
||||||
|
" 'QMJSQUHRW': 'JPQMJSQUHRW1',\n",
|
||||||
|
" '3S41ORQEE': '7E3S41ORQEE0',\n",
|
||||||
|
" '20S7FQUHA': 'D420S7FQUHAS',\n",
|
||||||
|
" '4MUPRNPGL': 'L24MUPRNPGLJ',\n",
|
||||||
|
" 'ILS5R11OM': 'UHILS5R11OM9',\n",
|
||||||
|
" 'BOPM5E8UC': 'C0BOPM5E8UC1',\n",
|
||||||
|
" 'KTVFADHQW': 'BVKTVFADHQWU',\n",
|
||||||
|
" 'WG9XKJNG4': 'EKWG9XKJNG4C',\n",
|
||||||
|
" 'KGYNL1828': 'DWKGYNL18285',\n",
|
||||||
|
" '2MDOX3R4V': 'JW2MDOX3R4V6',\n",
|
||||||
|
" 'KETIIHQRQ': 'EFKETIIHQRQK',\n",
|
||||||
|
" '1QENAC6BH': 'UJ1QENAC6BHO',\n",
|
||||||
|
" '8QYCT8M99': '2G8QYCT8M99D',\n",
|
||||||
|
" 'PX92YOBIQ': 'EVPX92YOBIQO',\n",
|
||||||
|
" '65GH7PAU8': '5665GH7PAU8H',\n",
|
||||||
|
" 'VHLXCVKYJ': 'CCVHLXCVKYJL',\n",
|
||||||
|
" 'OYV1JCEZ4': 'DROYV1JCEZ4R',\n",
|
||||||
|
" 'MV9HUKM9W': 'E0MV9HUKM9WZ',\n",
|
||||||
|
" '9ENELFA3J': 'R49ENELFA3J6',\n",
|
||||||
|
" 'XGND1P96B': 'BBXGND1P96BA',\n",
|
||||||
|
" 'C9VBH2SN1': 'L7C9VBH2SN13',\n",
|
||||||
|
" 'ORVUKAQQ3': '5VORVUKAQQ3X',\n",
|
||||||
|
" 'Y3RAQG0P7': '14Y3RAQG0P7G',\n",
|
||||||
|
" 'N4RMT14KJ': 'LDN4RMT14KJ1',\n",
|
||||||
|
" 'PM0IY5N3D': '4ZPM0IY5N3DD',\n",
|
||||||
|
" 'VI5Z8OHVJ': '4MVI5Z8OHVJT',\n",
|
||||||
|
" '2NG0MJU8R': 'Q22NG0MJU8RY',\n",
|
||||||
|
" 'DW335PYUU': '2SDW335PYUU2',\n",
|
||||||
|
" '0N60320LW': 'LP0N60320LWT',\n",
|
||||||
|
" '08MI510SO': '7D08MI510SOG',\n",
|
||||||
|
" '52ZIQZITA': 'QH52ZIQZITA0',\n",
|
||||||
|
" '6BCET1G6L': 'FE6BCET1G6LJ',\n",
|
||||||
|
" 'H8G5HA98Y': '3IH8G5HA98YW',\n",
|
||||||
|
" 'SPF213LIK': '9RSPF213LIK8',\n",
|
||||||
|
" '6XXFSL006': 'AX6XXFSL006E',\n",
|
||||||
|
" 'DIKIO64IS': 'D1DIKIO64ISV',\n",
|
||||||
|
" 'QZYUVYZQC': 'MCQZYUVYZQCR',\n",
|
||||||
|
" 'VQV13OB2D': 'B8VQV13OB2D2',\n",
|
||||||
|
" '1N6DI65EF': 'CN1N6DI65EFU',\n",
|
||||||
|
" '5A1CFMFDW': 'VW5A1CFMFDWT',\n",
|
||||||
|
" '6UDJNGDLV': 'U46UDJNGDLV4',\n",
|
||||||
|
" '4CXZ7E03G': 'OF4CXZ7E03G1',\n",
|
||||||
|
" 'DGXKVLWI6': 'YWDGXKVLWI63',\n",
|
||||||
|
" '6EL1HRO37': 'K16EL1HRO37L',\n",
|
||||||
|
" 'MZA4PZHN1': 'B4MZA4PZHN1X',\n",
|
||||||
|
" 'H4J8AA9D9': 'VBH4J8AA9D9K',\n",
|
||||||
|
" '94X7BM5YH': 'R394X7BM5YHD',\n",
|
||||||
|
" 'D4W6LP8DS': 'TKD4W6LP8DSB',\n",
|
||||||
|
" 'XLB6X775W': '9WXLB6X775WV',\n",
|
||||||
|
" 'UJ3IXRHOQ': '1DUJ3IXRHOQH',\n",
|
||||||
|
" 'F4D5ULQS2': '16F4D5ULQS2N',\n",
|
||||||
|
" 'OK1OYP6UH': '8GOK1OYP6UHP',\n",
|
||||||
|
" 'C4XAN8ZQX': 'WLC4XAN8ZQXC',\n",
|
||||||
|
" 'Z1C4LXNUX': 'XZZ1C4LXNUXK',\n",
|
||||||
|
" 'UR893BUIO': 'UUUR893BUIOM',\n",
|
||||||
|
" '2MHFMCKXB': 'MS2MHFMCKXBG',\n",
|
||||||
|
" 'WV9GSZ9Y9': '1HWV9GSZ9Y90',\n",
|
||||||
|
" 'DJVCDACM4': '3CDJVCDACM4E',\n",
|
||||||
|
" 'UD9WEX3MI': 'PLUD9WEX3MIP',\n",
|
||||||
|
" 'AO9E1G23K': '4HAO9E1G23K9',\n",
|
||||||
|
" '314RD6J53': 'J8314RD6J53P',\n",
|
||||||
|
" 'ZWTCGE82T': 'XPZWTCGE82T3',\n",
|
||||||
|
" 'AQWM6ZAXA': '43AQWM6ZAXAE',\n",
|
||||||
|
" 'XYT8UANE5': 'CEXYT8UANE5W',\n",
|
||||||
|
" 'HBX2NV1WU': 'GAHBX2NV1WUX',\n",
|
||||||
|
" 'YARFVQ8NV': '2WYARFVQ8NVH',\n",
|
||||||
|
" 'Q8XRD3O7U': 'D5Q8XRD3O7U7',\n",
|
||||||
|
" 'T944EOPRH': 'B9T944EOPRHF',\n",
|
||||||
|
" 'S9KI8ZAIS': 'MWS9KI8ZAISX',\n",
|
||||||
|
" 'K9JVRFD7P': 'F1K9JVRFD7PC',\n",
|
||||||
|
" 'TQLAT8HYQ': 'HKTQLAT8HYQC',\n",
|
||||||
|
" '2WF3FK3WK': '0M2WF3FK3WKP',\n",
|
||||||
|
" 'FMK7CUIQ6': 'FFFMK7CUIQ6O',\n",
|
||||||
|
" 'W35ZP4CJT': 'FDW35ZP4CJT6',\n",
|
||||||
|
" 'GZVXIVFA5': 'FCGZVXIVFA5A',\n",
|
||||||
|
" 'G60QFWBI6': '01G60QFWBI6L',\n",
|
||||||
|
" 'VSWK4HZ48': 'K6VSWK4HZ48F',\n",
|
||||||
|
" 'JC17GDPYL': '6JJC17GDPYLT',\n",
|
||||||
|
" 'GLM2KKVDO': 'RMGLM2KKVDOT',\n",
|
||||||
|
" 'A1PKFD4SI': 'VVA1PKFD4SI6',\n",
|
||||||
|
" '6M3STNR7D': 'ZS6M3STNR7DT',\n",
|
||||||
|
" 'LD9SU4M2K': 'K5LD9SU4M2K5',\n",
|
||||||
|
" '7OUQU2N9E': '5N7OUQU2N9EL',\n",
|
||||||
|
" 'O7KSY41NX': '2VO7KSY41NX3',\n",
|
||||||
|
" 'VAAQH72VE': 'AMVAAQH72VE1',\n",
|
||||||
|
" '4TIJDRJXK': '4V4TIJDRJXK4',\n",
|
||||||
|
" 'O2W8LBQST': '3XO2W8LBQST8',\n",
|
||||||
|
" '2FZBFCPBC': 'O82FZBFCPBCW',\n",
|
||||||
|
" 'CR8BIQRJI': 'PDCR8BIQRJIE',\n",
|
||||||
|
" '9ATM3C2QF': 'Y49ATM3C2QFG',\n",
|
||||||
|
" 'A9K6ODETN': '1NA9K6ODETNQ',\n",
|
||||||
|
" 'WSF8ODG6K': 'JFWSF8ODG6KL',\n",
|
||||||
|
" '97QHJYVGS': 'SH97QHJYVGS6',\n",
|
||||||
|
" 'S11Q6D74C': '06S11Q6D74CF',\n",
|
||||||
|
" '4I010H2FG': 'PS4I010H2FGF',\n",
|
||||||
|
" 'LB8DJ50W7': 'LSLB8DJ50W7Y',\n",
|
||||||
|
" 'BWJEI2ZWW': '2FBWJEI2ZWWW',\n",
|
||||||
|
" 'J6Z8TUP17': '53J6Z8TUP17K',\n",
|
||||||
|
" '6SKFIUQQR': 'FF6SKFIUQQRI',\n",
|
||||||
|
" '21752X5I4': '3P21752X5I4H',\n",
|
||||||
|
" 'EBJRHI9MX': 'BEEBJRHI9MXO',\n",
|
||||||
|
" 'CGIM8212C': 'TKCGIM8212CA',\n",
|
||||||
|
" 'ZTAT58MP9': 'PSZTAT58MP9X',\n",
|
||||||
|
" '2C53MI58E': 'EQ2C53MI58EK',\n",
|
||||||
|
" '2J6MVBDXF': 'WD2J6MVBDXF4',\n",
|
||||||
|
" 'VUZB8LZWG': 'L6VUZB8LZWGC',\n",
|
||||||
|
" '24NAR0P4U': '2T24NAR0P4UQ',\n",
|
||||||
|
" 'QIURVPPEU': '2VQIURVPPEUN',\n",
|
||||||
|
" '22MOPDBE5': 'CZ22MOPDBE5Q',\n",
|
||||||
|
" 'QIR9UC0C2': '0XQIR9UC0C21',\n",
|
||||||
|
" 'EBWFR1675': '6SEBWFR16758',\n",
|
||||||
|
" 'VQY0DPD4Y': 'YEVQY0DPD4Y5',\n",
|
||||||
|
" 'HIO7012J3': 'BIHIO7012J3V',\n",
|
||||||
|
" '82LO8UAOF': 'SE82LO8UAOFG',\n",
|
||||||
|
" 'M4F3A801F': 'P4M4F3A801FS',\n",
|
||||||
|
" 'VEWNXX8LJ': 'QUVEWNXX8LJA',\n",
|
||||||
|
" 'DR9BZILYK': 'K4DR9BZILYKE',\n",
|
||||||
|
" 'WUNNTQEZ1': '71WUNNTQEZ12',\n",
|
||||||
|
" 'ZDEFTB1IL': 'DBZDEFTB1ILD',\n",
|
||||||
|
" 'W4THBWTKG': '1RW4THBWTKGQ',\n",
|
||||||
|
" '5IFM62ER1': '1M5IFM62ER16',\n",
|
||||||
|
" 'WUCK7DERX': '5GWUCK7DERX6',\n",
|
||||||
|
" 'JSVFCY8HF': 'GAJSVFCY8HF0',\n",
|
||||||
|
" 'QO47CZIXH': 'FNQO47CZIXHC',\n",
|
||||||
|
" 'F9796AJTQ': '32F9796AJTQX',\n",
|
||||||
|
" 'AYMKEUSED': '2HAYMKEUSEDH',\n",
|
||||||
|
" '8MCTP6LWD': 'N28MCTP6LWD8',\n",
|
||||||
|
" 'BFAS6L19T': '6OBFAS6L19T0',\n",
|
||||||
|
" '52YR1ZQIH': 'LM52YR1ZQIHC',\n",
|
||||||
|
" 'DB4KB8J2L': 'ZBDB4KB8J2LY',\n",
|
||||||
|
" 'PWSKN1AY9': '25PWSKN1AY9B',\n",
|
||||||
|
" 'TLYW6AO5H': '2STLYW6AO5HL',\n",
|
||||||
|
" '8Y7Z0XZ62': 'UR8Y7Z0XZ62G',\n",
|
||||||
|
" 'UEUJA1ZVQ': 'RXUEUJA1ZVQX',\n",
|
||||||
|
" 'MKFMF3HPG': 'T7MKFMF3HPGR',\n",
|
||||||
|
" 'F1ID3TSTM': '8TF1ID3TSTMR',\n",
|
||||||
|
" '43V04ZM3O': '2L43V04ZM3OB',\n",
|
||||||
|
" 'Q9Q42W5Y4': 'RDQ9Q42W5Y40',\n",
|
||||||
|
" 'VLMQE8WPZ': 'VFVLMQE8WPZO',\n",
|
||||||
|
" 'YB4GUPUS5': 'WXYB4GUPUS59',\n",
|
||||||
|
" 'A63RRAJD8': 'JYA63RRAJD8G',\n",
|
||||||
|
" '3E7EIAYAM': 'RH3E7EIAYAM1',\n",
|
||||||
|
" 'Z4OTO9L6S': 'NOZ4OTO9L6SE',\n",
|
||||||
|
" 'T13YH6FP1': 'A4T13YH6FP1H',\n",
|
||||||
|
" '81B435UP4': 'Y381B435UP4Y',\n",
|
||||||
|
" '0FPSHDFIP': 'ZC0FPSHDFIPJ',\n",
|
||||||
|
" 'AVNJ3J8EL': 'FYAVNJ3J8EL0',\n",
|
||||||
|
" 'MLZ4DL6C4': 'Z3MLZ4DL6C4K',\n",
|
||||||
|
" 'U8RG5JYKX': 'ELU8RG5JYKXC',\n",
|
||||||
|
" 'HXS6LRFRT': 'ZAHXS6LRFRTQ',\n",
|
||||||
|
" '5ZLIRONWF': '8G5ZLIRONWFS',\n",
|
||||||
|
" '9VOO2RY6B': 'TT9VOO2RY6BS',\n",
|
||||||
|
" '5MU5HIVFA': '2U5MU5HIVFAF',\n",
|
||||||
|
" 'PNTYGS7BB': 'K7PNTYGS7BB6',\n",
|
||||||
|
" 'TSY11I09H': 'W5TSY11I09HX',\n",
|
||||||
|
" 'TLQ0M2ZJ7': 'MOTLQ0M2ZJ7I',\n",
|
||||||
|
" 'K7EHZR3G0': '9HK7EHZR3G0A',\n",
|
||||||
|
" 'DWBUGK7S4': 'XYDWBUGK7S43',\n",
|
||||||
|
" '3YV8BFMQD': 'O03YV8BFMQDC',\n",
|
||||||
|
" 'ZXHPB7PK5': 'MOZXHPB7PK52',\n",
|
||||||
|
" 'G09228B46': 'GGG09228B46H',\n",
|
||||||
|
" '3T7X2XUJE': 'P03T7X2XUJE0',\n",
|
||||||
|
" 'MQRVEO5XK': 'O1MQRVEO5XK6',\n",
|
||||||
|
" 'W729BG75C': 'PGW729BG75CJ',\n",
|
||||||
|
" 'YZ42LKOC3': 'FXYZ42LKOC3V',\n",
|
||||||
|
" 'MX7W2VVFL': 'BGMX7W2VVFLM',\n",
|
||||||
|
" '9TE099FQF': 'S99TE099FQF6',\n",
|
||||||
|
" 'RK5TXUFDB': 'R4RK5TXUFDBY',\n",
|
||||||
|
" 'FWDV43CLD': 'Q2FWDV43CLDJ',\n",
|
||||||
|
" '6J06KB15V': 'NM6J06KB15VZ',\n",
|
||||||
|
" 'P8GK81MZW': 'JIP8GK81MZW2',\n",
|
||||||
|
" 'OCW1CCQYS': '1VOCW1CCQYSV',\n",
|
||||||
|
" '4VHE6PI7F': '3H4VHE6PI7FR',\n",
|
||||||
|
" 'B15P0OYCN': 'NMB15P0OYCN8',\n",
|
||||||
|
" 'HA9C7RUAE': 'Y8HA9C7RUAE1',\n",
|
||||||
|
" 'QYFKO5546': 'EZQYFKO5546D',\n",
|
||||||
|
" '6F39T0NNB': '8A6F39T0NNBF',\n",
|
||||||
|
" 'D3N2HOB8Z': 'BHD3N2HOB8Z0',\n",
|
||||||
|
" 'HP1X4MNKD': '5OHP1X4MNKDK',\n",
|
||||||
|
" 'L0DD0ULT7': 'D7L0DD0ULT75',\n",
|
||||||
|
" 'MCV4GR0T0': '7KMCV4GR0T0I',\n",
|
||||||
|
" 'GVV7VU5LH': 'XTGVV7VU5LH0',\n",
|
||||||
|
" '7YQB5N9L2': 'G77YQB5N9L20',\n",
|
||||||
|
" 'OYP9WS1O6': 'WHOYP9WS1O63',\n",
|
||||||
|
" '321QRIN7X': 'EQ321QRIN7X4',\n",
|
||||||
|
" '0SWQ37SIX': 'YL0SWQ37SIX0',\n",
|
||||||
|
" 'DQLJG0QP8': 'PZDQLJG0QP82',\n",
|
||||||
|
" 'VREINDO2Z': 'I7VREINDO2ZC',\n",
|
||||||
|
" '0LLTRFT38': 'H10LLTRFT38Q',\n",
|
||||||
|
" 'ETUMPHYK3': 'RUETUMPHYK3F',\n",
|
||||||
|
" '3G6U150HG': 'L93G6U150HGB',\n",
|
||||||
|
" '7QN7HCHNI': 'VH7QN7HCHNIV',\n",
|
||||||
|
" '64CVRL0QR': 'G164CVRL0QRI',\n",
|
||||||
|
" 'NEO6G19L7': 'I8NEO6G19L7C',\n",
|
||||||
|
" '4MDIHCUQU': 'BJ4MDIHCUQUF',\n",
|
||||||
|
" '9VS7VBHI4': 'RW9VS7VBHI4G',\n",
|
||||||
|
" '1YH0F2QOD': 'O11YH0F2QODF',\n",
|
||||||
|
" 'QHISI6VK0': 'U5QHISI6VK0L',\n",
|
||||||
|
" '4QVCWPICV': 'JJ4QVCWPICV6',\n",
|
||||||
|
" 'QPI42MT9F': 'PLQPI42MT9FF',\n",
|
||||||
|
" 'HCCYG0AC"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 213,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/html": [
|
||||||
|
"<b>limit_output extension: Maximum message size of 10000 exceeded with 30005 characters</b>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.8.10"
|
||||||
|
},
|
||||||
|
"toc": {
|
||||||
|
"base_numbering": 1,
|
||||||
|
"nav_menu": {},
|
||||||
|
"number_sections": true,
|
||||||
|
"sideBar": true,
|
||||||
|
"skip_h1_title": false,
|
||||||
|
"title_cell": "Table of Contents",
|
||||||
|
"title_sidebar": "Contents",
|
||||||
|
"toc_cell": false,
|
||||||
|
"toc_position": {},
|
||||||
|
"toc_section_display": true,
|
||||||
|
"toc_window_display": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
|
}
|
||||||
0
code/misc/python/scripts/convolution.ipynb
Normal file
0
code/misc/python/scripts/convolution.ipynb
Normal file
0
code/misc/python/scripts/gpu.ipynb
Normal file
0
code/misc/python/scripts/gpu.ipynb
Normal file
67
code/misc/python/scripts/pdfmerge.py
Normal file
67
code/misc/python/scripts/pdfmerge.py
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
import sys
|
||||||
|
try:
|
||||||
|
from PyPDF2 import PdfFileReader, PdfFileWriter,PdfFileMerger
|
||||||
|
except ImportError:
|
||||||
|
from pyPdf import PdfFileReader, PdfFileWriter
|
||||||
|
|
||||||
|
def pdf_merge(input_files, output_stream, rotation=0):
|
||||||
|
input_streams = []
|
||||||
|
try:
|
||||||
|
# First open all the files, then produce the output file, and
|
||||||
|
# finally close the input files. This is necessary because
|
||||||
|
# the data isn't read from the input files until the write
|
||||||
|
# operation. Thanks to
|
||||||
|
# https://stackoverflow.com/questions/6773631/problem-with-closing-python-pypdf-writing-getting-a-valueerror-i-o-operation/6773733#6773733
|
||||||
|
for input_file in input_files:
|
||||||
|
input_streams.append(open(input_file, 'rb'))
|
||||||
|
writer = PdfFileWriter()
|
||||||
|
for reader in map(PdfFileReader, input_streams):
|
||||||
|
for n in range(reader.getNumPages()):
|
||||||
|
page=reader.getPage(n)
|
||||||
|
page.rotateClockwise(rotation)
|
||||||
|
writer.addPage(page)
|
||||||
|
writer.write(output_stream)
|
||||||
|
finally:
|
||||||
|
for f in input_streams:
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def fileslist (directorypath):
|
||||||
|
import glob, os
|
||||||
|
files= glob.glob(directorypath+'/*.pdf')
|
||||||
|
return files
|
||||||
|
|
||||||
|
|
||||||
|
def pdf_cat(input_files, outputfilename="results.pdf"):
|
||||||
|
pdfs = input_files
|
||||||
|
merger = PdfFileMerger()
|
||||||
|
|
||||||
|
for pdf in pdfs:
|
||||||
|
merger.append(PdfFileReader(pdf, 'rb'))
|
||||||
|
|
||||||
|
merger.write(outputfilename)
|
||||||
|
merger.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if sys.platform == "win32":
|
||||||
|
import os, msvcrt
|
||||||
|
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
|
||||||
|
|
||||||
|
#pdf_cat(sys.argv[1:], sys.stdout)
|
||||||
|
output_path=r'/home/dl92/Documents/DigitalPaper/Upload/merged.pdf'
|
||||||
|
output_path2=r'/home/dl92/Documents/DigitalPaper/Upload/Firework Maker.pdf'
|
||||||
|
files=fileslist(r'/home/dl92/Documents/DigitalPaper/Upload')
|
||||||
|
files.sort()
|
||||||
|
output_stream = open(output_path, 'wb')
|
||||||
|
pdf_merge(files[0:5] ,output_stream,90)
|
||||||
|
output_stream.close()
|
||||||
|
|
||||||
|
output_stream = open(output_path2, 'wb')
|
||||||
|
pdf_merge([output_path]+files[5:7] ,output_stream,0)
|
||||||
|
output_stream.close()
|
||||||
|
#pdf_merge(fileslist(r'/home/dl92/Documents/DigitalPaper/Upload'),output_stream)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
62
code/misc/python/scripts/pdfparser.py
Normal file
62
code/misc/python/scripts/pdfparser.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
|
||||||
|
import sys,os
|
||||||
|
import streamlit as st
|
||||||
|
import ptvsd
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
st.header('sdfsdfs')
|
||||||
|
st.write(sys.executable)
|
||||||
|
st.write(sys.version)
|
||||||
|
st.write(sys.builtin_module_names)
|
||||||
|
|
||||||
|
|
||||||
|
st.header('sdfsdfs')
|
||||||
|
|
||||||
|
|
||||||
|
#ptvsd.enable_attach()#, redirect_output=True)
|
||||||
|
#ptvsd.wait_for_attach()
|
||||||
|
|
||||||
|
print("hello World")
|
||||||
|
#####
|
||||||
|
|
||||||
|
|
||||||
|
import PyPDF2
|
||||||
|
pwd=r'n7E;~||ZOs+sDuptXAu'
|
||||||
|
filename='/home/dl92/Downloads/PGPMessage.pdf'
|
||||||
|
filename='/home/dl92/Downloads/Transaction.pdf'
|
||||||
|
pdfFileObj = open(filename,'rb') #'rb' for read binary mode
|
||||||
|
pdfFile = PyPDF2.PdfFileReader(pdfFileObj)
|
||||||
|
|
||||||
|
if pdfFile.isEncrypted:
|
||||||
|
try:
|
||||||
|
pdfFile.decrypt(pwd)
|
||||||
|
print('File Decrypted (PyPDF2)')
|
||||||
|
except:
|
||||||
|
command = ("cp "+ filename +
|
||||||
|
" temp.pdf; qpdf --password=n7E;~||ZOs+sDuptXAu --decrypt temp.pdf " + filename
|
||||||
|
+ "; rm temp.pdf")
|
||||||
|
print (command)
|
||||||
|
os.system(command)
|
||||||
|
print('File Decrypted (qpdf)')
|
||||||
|
fp = open(filename)
|
||||||
|
pdfFile = PyPDF2.PdfFileReader(fp)
|
||||||
|
|
||||||
|
|
||||||
|
print(pdfFile.numPages)
|
||||||
|
pageObj = pdfFile.getPage(2) #'9' is the page number
|
||||||
|
pageObj.extractText()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
st.header('sdfsdfs')
|
||||||
|
|
||||||
|
for i in range(1, 40):
|
||||||
|
st.write(i)
|
||||||
|
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
print (pd.__name__)
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
302
code/misc/python/scripts/pivottable-qgrid.ipynb
Normal file
302
code/misc/python/scripts/pivottable-qgrid.ipynb
Normal file
File diff suppressed because one or more lines are too long
127
code/misc/python/scripts/studenttprocess.ipynb
Normal file
127
code/misc/python/scripts/studenttprocess.ipynb
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 16,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import numpy as np\n",
|
||||||
|
"import scipy as sc\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"from matplotlib import pyplot as plt\n",
|
||||||
|
"from scipy import stats \n",
|
||||||
|
"from IPython.core.interactiveshell import InteractiveShell\n",
|
||||||
|
"InteractiveShell.ast_node_interactivity = \"all\"\n",
|
||||||
|
"\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 52,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"KstestResult(statistic=0.0019255354784954437, pvalue=0.8515501507924718, statistic_location=-0.003026398265409117, statistic_sign=1)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 52,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"KstestResult(statistic=0.0019317484822836684, pvalue=0.8488394389115358, statistic_location=-0.003041920835342991, statistic_sign=1)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 52,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"rng = np.random.default_rng()#(seed=1234)\n",
|
||||||
|
"dof=100\n",
|
||||||
|
"size=(100000)\n",
|
||||||
|
"dt=15/365\n",
|
||||||
|
"sqrtdt=np.sqrt(dt)\n",
|
||||||
|
"sfactor=np.sqrt((dof-2)/dof)\n",
|
||||||
|
"\n",
|
||||||
|
"#np.sqrt(1/np.random.gamma(dof/2,dof/2,nsims))\n",
|
||||||
|
"\n",
|
||||||
|
"N=rng.normal(0,sqrtdt,size)\n",
|
||||||
|
"W=1/np.sqrt(rng.chisquare(dof,size)/dof)\n",
|
||||||
|
"T=sfactor*N*W\n",
|
||||||
|
"\n",
|
||||||
|
"stats.kstest(N,\"norm\",args=(0,sqrtdt))\n",
|
||||||
|
"assert stats.kstest(N,\"norm\",args=(0,sqrtdt)).pvalue>0.05 #accept null of normality\n",
|
||||||
|
"\n",
|
||||||
|
"stats.kstest(T,\"t\",args=(dof,0,sfactor*sqrtdt))\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"#stats.kstest(T,T1)\n",
|
||||||
|
"\n",
|
||||||
|
"#pd.Series(T).describe()\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 50,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"array([0.04109589, 0.08219178, 0.12328767, 0.16438356, 0.20547945,\n",
|
||||||
|
" 0.24657534, 0.28767123, 0.32876712, 0.36986301, 0.4109589 ,\n",
|
||||||
|
" 0.45205479, 0.49315068, 0.53424658, 0.57534247, 0.61643836,\n",
|
||||||
|
" 0.65753425, 0.69863014, 0.73972603, 0.78082192, 0.82191781,\n",
|
||||||
|
" 0.8630137 , 0.90410959, 0.94520548, 0.98630137])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 50,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"days=np.arange(15,365,15)\n",
|
||||||
|
"timegrid=days/365\n",
|
||||||
|
"\n",
|
||||||
|
"timegrid"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Main",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.11.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
490
code/misc/python/scripts/tax calculator.ipynb
Normal file
490
code/misc/python/scripts/tax calculator.ipynb
Normal file
@@ -0,0 +1,490 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 37,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"incometax_bands=[(0,37500,0.2),(37500,150000,0.4),(150000,1e9,0.45)]\n",
|
||||||
|
"NI_bands=[(0,8632,0),(8632,50000,0.12),(50000,1e9,0.02)]\n",
|
||||||
|
"NI_bands_emp=[(0,8632,0),(8632,1e9,0.138)]\n",
|
||||||
|
"dividends=[(0,2000,0),(37500,150000,0.4),(150000,1e9,0.45)]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 38,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"weekly\n",
|
||||||
|
"daily_rate=950\n",
|
||||||
|
"gross_salary=lambda x:daily_rate*x\n",
|
||||||
|
"incometax= lambda x: taxcalc(x,incometax_bands) \n",
|
||||||
|
"employeeNI= lambda x: taxcalc(x,NI_bands) \n",
|
||||||
|
"employerNI= lambda x: taxcalc(x,NI_bands_emp) "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 39,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def taxcalc (grosssalary, taxbands):\n",
|
||||||
|
" tax=0\n",
|
||||||
|
" for lb,ub,rate in taxbands:\n",
|
||||||
|
" if grosssalary< lb:\n",
|
||||||
|
" continue\n",
|
||||||
|
" elif (grosssalary>=lb) and (grosssalary<ub):\n",
|
||||||
|
" tax+=(grosssalary-lb)*rate\n",
|
||||||
|
" else:\n",
|
||||||
|
" tax+=(ub-lb)*rate\n",
|
||||||
|
" return tax\n",
|
||||||
|
" \n",
|
||||||
|
"def effective_paye_taxrate(numdays):\n",
|
||||||
|
" gross=gross_salary(numdays)\n",
|
||||||
|
" return (incometax(gross)+employeeNI(gross))/gross\n",
|
||||||
|
" \n",
|
||||||
|
"def effective_bnp_taxrate(numdays):\n",
|
||||||
|
" gross=gross_salary(numdays)\n",
|
||||||
|
" return (incometax(gross)+employeeNI(gross)+employerNI(gross))/gross \n",
|
||||||
|
"\n",
|
||||||
|
"def effective_bnp_taxrate2(numdays):\n",
|
||||||
|
" gross=gross_salary(numdays)\n",
|
||||||
|
" grossminusNI=gross-employerNI(gross)\n",
|
||||||
|
" return (incometax(grossminusNI)+employeeNI(grossminusNI)+employerNI(gross))/gross \n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 40,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"[(1, 950, 0.0),\n",
|
||||||
|
" (2, 1900, 0.0),\n",
|
||||||
|
" (3, 2850, 0.0),\n",
|
||||||
|
" (4, 3800, 0.0),\n",
|
||||||
|
" (5, 4750, 0.0),\n",
|
||||||
|
" (6, 5700, 0.0),\n",
|
||||||
|
" (7, 6650, 0.0),\n",
|
||||||
|
" (8, 7600, 0.0),\n",
|
||||||
|
" (9, 8550, 0.0),\n",
|
||||||
|
" (10, 9500, 0.00857401263157892),\n",
|
||||||
|
" (11, 10450, 0.016325466028708158),\n",
|
||||||
|
" (12, 11400, 0.02278501052631582),\n",
|
||||||
|
" (13, 12350, 0.028250778947368382),\n",
|
||||||
|
" (14, 13300, 0.03293572330827074),\n",
|
||||||
|
" (15, 14250, 0.03699600842105266),\n",
|
||||||
|
" (16, 15200, 0.040548757894736887),\n",
|
||||||
|
" (17, 16150, 0.04368353684210524),\n",
|
||||||
|
" (18, 17100, 0.046470007017543835),\n",
|
||||||
|
" (19, 18050, 0.04896316454293631),\n",
|
||||||
|
" (20, 19000, 0.05120700631578945),\n",
|
||||||
|
" (21, 19950, 0.05323714887218045),\n",
|
||||||
|
" (22, 20900, 0.055082733014354124),\n",
|
||||||
|
" (23, 21850, 0.056767831578947325),\n",
|
||||||
|
" (24, 22800, 0.0583125052631579),\n",
|
||||||
|
" (25, 23750, 0.05973360505263159),\n",
|
||||||
|
" (26, 24700, 0.06104538947368421),\n",
|
||||||
|
" (27, 25650, 0.06226000467836268),\n",
|
||||||
|
" (28, 26600, 0.0633878616541354),\n",
|
||||||
|
" (29, 27550, 0.0644379353901996),\n",
|
||||||
|
" (30, 28500, 0.06541800421052635),\n",
|
||||||
|
" (31, 29450, 0.0663348427843804),\n",
|
||||||
|
" (32, 30400, 0.0671943789473684),\n",
|
||||||
|
" (33, 31350, 0.06800182200956939),\n",
|
||||||
|
" (34, 32300, 0.0687617684210527),\n",
|
||||||
|
" (35, 33250, 0.06947828932330824),\n",
|
||||||
|
" (36, 34200, 0.07015500350877196),\n",
|
||||||
|
" (37, 35150, 0.07079513854907543),\n",
|
||||||
|
" (38, 36100, 0.07140158227146814),\n",
|
||||||
|
" (39, 37050, 0.07197692631578945),\n",
|
||||||
|
" (40, 38000, 0.06989192421052631),\n",
|
||||||
|
" (41, 38950, 0.06559797483953783),\n",
|
||||||
|
" (42, 39900, 0.06150849924812035),\n",
|
||||||
|
" (43, 40850, 0.05760923182374539),\n",
|
||||||
|
" (44, 41800, 0.05388720382775125),\n",
|
||||||
|
" (45, 42750, 0.05286494315789475),\n",
|
||||||
|
" (46, 43700, 0.05315570526315794),\n",
|
||||||
|
" (47, 44650, 0.05343409451287795),\n",
|
||||||
|
" (48, 45600, 0.05370088421052627),\n",
|
||||||
|
" (49, 46550, 0.05395678453276048),\n",
|
||||||
|
" (50, 47500, 0.05420244884210529),\n",
|
||||||
|
" (51, 48450, 0.05443847925696599),\n",
|
||||||
|
" (52, 49400, 0.05466543157894743),\n",
|
||||||
|
" (53, 50350, 0.0555789537239324),\n",
|
||||||
|
" (54, 51300, 0.057628232358674425),\n",
|
||||||
|
" (55, 52250, 0.05960299177033496),\n",
|
||||||
|
" (56, 53200, 0.06150722406015041),\n",
|
||||||
|
" (57, 54150, 0.0633446411819022),\n",
|
||||||
|
" (58, 55100, 0.06511869909255902),\n",
|
||||||
|
" (59, 56050, 0.06683261944692237),\n",
|
||||||
|
" (60, 57000, 0.06791885473684212),\n",
|
||||||
|
" (61, 57950, 0.06811756203623826),\n",
|
||||||
|
" (62, 58900, 0.06830985942275053),\n",
|
||||||
|
" (63, 59850, 0.06849605213032589),\n",
|
||||||
|
" (64, 60800, 0.06867642631578946),\n",
|
||||||
|
" (65, 61750, 0.06885125052631574),\n",
|
||||||
|
" (66, 62700, 0.06902077703349285),\n",
|
||||||
|
" (67, 63650, 0.06918524304791834),\n",
|
||||||
|
" (68, 64600, 0.06934487182662535),\n",
|
||||||
|
" (69, 65550, 0.06949987368421057),\n",
|
||||||
|
" (70, 66500, 0.06965044691729322),\n",
|
||||||
|
" (71, 67450, 0.0697967786508526),\n",
|
||||||
|
" (72, 68400, 0.06993904561403508),\n",
|
||||||
|
" (73, 69350, 0.07007741485219904),\n",
|
||||||
|
" (74, 70300, 0.07021204438122336),\n",
|
||||||
|
" (75, 71250, 0.07034308378947374),\n",
|
||||||
|
" (76, 72200, 0.07047067479224373),\n",
|
||||||
|
" (77, 73150, 0.0705949517429939),\n",
|
||||||
|
" (78, 74100, 0.07071604210526322),\n",
|
||||||
|
" (79, 75050, 0.07083406688874089),\n",
|
||||||
|
" (80, 76000, 0.07094914105263167),\n",
|
||||||
|
" (81, 76950, 0.0710613738791423),\n",
|
||||||
|
" (82, 77900, 0.07117086931964056),\n",
|
||||||
|
" (83, 78850, 0.07127772631578949),\n",
|
||||||
|
" (84, 79800, 0.07138203909774432),\n",
|
||||||
|
" (85, 80750, 0.0714838974613003),\n",
|
||||||
|
" (86, 81700, 0.07158338702570372),\n",
|
||||||
|
" (87, 82650, 0.07168058947368433),\n",
|
||||||
|
" (88, 83600, 0.07177558277511964),\n",
|
||||||
|
" (89, 84550, 0.07186844139562382),\n",
|
||||||
|
" (90, 85500, 0.07195923649122815),\n",
|
||||||
|
" (91, 86450, 0.07204803609022559),\n",
|
||||||
|
" (92, 87400, 0.07213490526315786),\n",
|
||||||
|
" (93, 88350, 0.07221990628183367),\n",
|
||||||
|
" (94, 89300, 0.07230309876819707),\n",
|
||||||
|
" (95, 90250, 0.072384539833795),\n",
|
||||||
|
" (96, 91200, 0.07246428421052625),\n",
|
||||||
|
" (97, 92150, 0.07254238437330435),\n",
|
||||||
|
" (98, 93100, 0.07261889065520943),\n",
|
||||||
|
" (99, 94050, 0.07269385135566186),\n",
|
||||||
|
" (100, 95000, 0.07276731284210519),\n",
|
||||||
|
" (101, 95950, 0.07283931964564871),\n",
|
||||||
|
" (102, 96900, 0.07290991455108359),\n",
|
||||||
|
" (103, 97850, 0.07297913868165556),\n",
|
||||||
|
" (104, 98800, 0.07304703157894732),\n",
|
||||||
|
" (105, 99750, 0.07311363127819548),\n",
|
||||||
|
" (106, 100700, 0.07317897437934462),\n",
|
||||||
|
" (107, 101650, 0.07324309611411706),\n",
|
||||||
|
" (108, 102600, 0.07330603040935668),\n",
|
||||||
|
" (109, 103550, 0.07336780994688552),\n",
|
||||||
|
" (110, 104500, 0.07342846622009563),\n",
|
||||||
|
" (111, 105450, 0.07348802958748224),\n",
|
||||||
|
" (112, 106400, 0.0735465293233083),\n",
|
||||||
|
" (113, 107350, 0.0736039936655799),\n",
|
||||||
|
" (114, 108300, 0.07366044986149584),\n",
|
||||||
|
" (115, 109250, 0.07371592421052625),\n",
|
||||||
|
" (116, 110200, 0.07377044210526318),\n",
|
||||||
|
" (117, 111150, 0.07382402807017546),\n",
|
||||||
|
" (118, 112100, 0.07387670579839428),\n",
|
||||||
|
" (119, 113050, 0.07392849818664304),\n",
|
||||||
|
" (120, 114000, 0.073979427368421),\n",
|
||||||
|
" (121, 114950, 0.07402951474554148),\n",
|
||||||
|
" (122, 115900, 0.07407878101811899),\n",
|
||||||
|
" (123, 116850, 0.07412724621309374),\n",
|
||||||
|
" (124, 117800, 0.07417492971137518),\n",
|
||||||
|
" (125, 118750, 0.07422185027368416),\n",
|
||||||
|
" (126, 119700, 0.07426802606516286),\n",
|
||||||
|
" (127, 120650, 0.07431347467882304),\n",
|
||||||
|
" (128, 121600, 0.07435821315789476),\n",
|
||||||
|
" (129, 122550, 0.07440225801713579),\n",
|
||||||
|
" (130, 123500, 0.0744456252631579),\n",
|
||||||
|
" (131, 124450, 0.07448833041382075),\n",
|
||||||
|
" (132, 125400, 0.07453038851674643),\n",
|
||||||
|
" (133, 126350, 0.07457181416699649),\n",
|
||||||
|
" (134, 127300, 0.07461262152395914),\n",
|
||||||
|
" (135, 128250, 0.07465282432748538),\n",
|
||||||
|
" (136, 129200, 0.0746924359133127),\n",
|
||||||
|
" (137, 130150, 0.07473146922781404),\n",
|
||||||
|
" (138, 131100, 0.07476993684210526),\n",
|
||||||
|
" (139, 132050, 0.07480785096554332),\n",
|
||||||
|
" (140, 133000, 0.07484522345864658),\n",
|
||||||
|
" (141, 133950, 0.0748820658454647),\n",
|
||||||
|
" (142, 134900, 0.07491838932542627),\n",
|
||||||
|
" (143, 135850, 0.07495420478468895),\n",
|
||||||
|
" (144, 136800, 0.07498952280701748),\n",
|
||||||
|
" (145, 137750, 0.07502435368421057),\n",
|
||||||
|
" (146, 138700, 0.07505870742609944),\n",
|
||||||
|
" (147, 139650, 0.07509259377013972),\n",
|
||||||
|
" (148, 140600, 0.07512602219061171),\n",
|
||||||
|
" (149, 141550, 0.07515900190745323),\n",
|
||||||
|
" (150, 142500, 0.07519154189473687),\n",
|
||||||
|
" (151, 143450, 0.07522365088881139),\n",
|
||||||
|
" (152, 144400, 0.07525533739612195),\n",
|
||||||
|
" (153, 145350, 0.07528660970072243),\n",
|
||||||
|
" (154, 146300, 0.07531747587149701),\n",
|
||||||
|
" (155, 147250, 0.0753479437691002),\n",
|
||||||
|
" (156, 148200, 0.07537802105263164),\n",
|
||||||
|
" (157, 149150, 0.07540771518605427),\n",
|
||||||
|
" (158, 150100, 0.07540372231845432),\n",
|
||||||
|
" (159, 151050, 0.07511841588877854),\n",
|
||||||
|
" (160, 152000, 0.07483667578947362),\n",
|
||||||
|
" (161, 152950, 0.0745584355671789),\n",
|
||||||
|
" (162, 153900, 0.0742836304093567),\n",
|
||||||
|
" (163, 154850, 0.07401219709396184),\n",
|
||||||
|
" (164, 155800, 0.0737440739409499),\n",
|
||||||
|
" (165, 156750, 0.0734792007655502),\n",
|
||||||
|
" (166, 157700, 0.07321751883322775),\n",
|
||||||
|
" (167, 158650, 0.07295897081626224),\n",
|
||||||
|
" (168, 159600, 0.0727035007518797),\n",
|
||||||
|
" (169, 160550, 0.07245105400186858),\n",
|
||||||
|
" (170, 161500, 0.0722015772136223),\n",
|
||||||
|
" (171, 162450, 0.07195501828254847),\n",
|
||||||
|
" (172, 163400, 0.07171132631578947),\n",
|
||||||
|
" (173, 164350, 0.07147045159720111),\n",
|
||||||
|
" (174, 165300, 0.07123234555353897),\n",
|
||||||
|
" (175, 166250, 0.07099696072180439),\n",
|
||||||
|
" (176, 167200, 0.07076425071770337),\n",
|
||||||
|
" (177, 168150, 0.070534170205174),\n",
|
||||||
|
" (178, 169100, 0.07030667486694264),\n",
|
||||||
|
" (179, 170050, 0.07008172137606583),\n",
|
||||||
|
" (180, 171000, 0.06985926736842096),\n",
|
||||||
|
" (181, 171950, 0.06963927141610937),\n",
|
||||||
|
" (182, 172900, 0.06948849924812028),\n",
|
||||||
|
" (183, 173850, 0.06950845280414147),\n",
|
||||||
|
" (184, 174800, 0.06952818947368422),\n",
|
||||||
|
" (185, 175750, 0.06954771277382643),\n",
|
||||||
|
" (186, 176700, 0.06956702614601018),\n",
|
||||||
|
" (187, 177650, 0.0695861329580636),\n",
|
||||||
|
" (188, 178600, 0.06960503650615907),\n",
|
||||||
|
" (189, 179550, 0.06962374001670835),\n",
|
||||||
|
" (190, 180500, 0.06964224664819935),\n",
|
||||||
|
" (191, 181450, 0.06966055949297328),\n",
|
||||||
|
" (192, 182400, 0.0696786815789473),\n",
|
||||||
|
" (193, 183350, 0.0696966158712844),\n",
|
||||||
|
" (194, 184300, 0.0697143652740097),\n",
|
||||||
|
" (195, 185250, 0.06973193263157895),\n",
|
||||||
|
" (196, 186200, 0.06974932073039741),\n",
|
||||||
|
" (197, 187150, 0.0697665323002939),\n",
|
||||||
|
" (198, 188100, 0.06978357001594893),\n",
|
||||||
|
" (199, 189050, 0.06980043649828088),\n",
|
||||||
|
" (200, 190000, 0.06981713431578945),\n",
|
||||||
|
" (201, 190950, 0.06983366598586027),\n",
|
||||||
|
" (202, 191900, 0.06985003397602912),\n",
|
||||||
|
" (203, 192850, 0.0698662407052113),\n",
|
||||||
|
" (204, 193800, 0.06988228854489165),\n",
|
||||||
|
" (205, 194750, 0.06989817982028235),\n",
|
||||||
|
" (206, 195700, 0.06991391681144615),\n",
|
||||||
|
" (207, 196650, 0.069929501754386),\n",
|
||||||
|
" (208, 197600, 0.06994493684210529),\n",
|
||||||
|
" (209, 198550, 0.0699602242256358),\n",
|
||||||
|
" (210, 199500, 0.06997536601503757),\n",
|
||||||
|
" (211, 200450, 0.06999036428036925),\n",
|
||||||
|
" (212, 201400, 0.07000522105263163),\n",
|
||||||
|
" (213, 202350, 0.07001993832468495),\n",
|
||||||
|
" (214, 203300, 0.07003451805213967),\n",
|
||||||
|
" (215, 204250, 0.07004896215422274),\n",
|
||||||
|
" (216, 205200, 0.07006327251461997),\n",
|
||||||
|
" (217, 206150, 0.0700774509822944),\n",
|
||||||
|
" (218, 207100, 0.07009149937228387),\n",
|
||||||
|
" (219, 208050, 0.07010541946647442),\n",
|
||||||
|
" (220, 209000, 0.07011921301435403),\n",
|
||||||
|
" (221, 209950, 0.07013288173374621),\n",
|
||||||
|
" (222, 210900, 0.07014642731152204),\n",
|
||||||
|
" (223, 211850, 0.07015985140429543),\n",
|
||||||
|
" (224, 212800, 0.07017315563909765),\n",
|
||||||
|
" (225, 213750, 0.07018634161403509),\n",
|
||||||
|
" (226, 214700, 0.07019941089892878),\n",
|
||||||
|
" (227, 215650, 0.07021236503593792),\n",
|
||||||
|
" (228, 216600, 0.07022520554016615),\n",
|
||||||
|
" (229, 217550, 0.07023793390025274),\n",
|
||||||
|
" (230, 218500, 0.07025055157894738),\n",
|
||||||
|
" (231, 219450, 0.07026306001367055),\n",
|
||||||
|
" (232, 220400, 0.07027546061705997),\n",
|
||||||
|
" (233, 221350, 0.07028775477750165),\n",
|
||||||
|
" (234, 222300, 0.0702999438596491),\n",
|
||||||
|
" (235, 223250, 0.07031202920492718),\n",
|
||||||
|
" (236, 224200, 0.07032401213202505),\n",
|
||||||
|
" (237, 225150, 0.07033589393737505),\n",
|
||||||
|
" (238, 226100, 0.07034767589562141),\n",
|
||||||
|
" (239, 227050, 0.07035935926007492),\n",
|
||||||
|
" (240, 228000, 0.07037094526315785),\n",
|
||||||
|
" (241, 228950, 0.07038243511683778),\n",
|
||||||
|
" (242, 229900, 0.07039383001304916),\n",
|
||||||
|
" (243, 230850, 0.07040513112410651),\n",
|
||||||
|
" (244, 231800, 0.07041633960310617),\n",
|
||||||
|
" (245, 232750, 0.07042745658431787),\n",
|
||||||
|
" (246, 233700, 0.07043848318356877),\n",
|
||||||
|
" (247, 234650, 0.07044942049861497),\n",
|
||||||
|
" (248, 235600, 0.07046026960950758),\n",
|
||||||
|
" (249, 236550, 0.0704710315789473)]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 40,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"[(x,gross_salary(x),effective_bnp_taxrate2(x)-effective_paye_taxrate(x)) for x in range(1,250)]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 47,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"net monthly salary paye 553.6629090909091\n",
|
||||||
|
"net monthly salary bnp1 427.9775272727273\n",
|
||||||
|
"net monthly salary bnp2 487.0496567272727\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"r1=effective_paye_taxrate(220)\n",
|
||||||
|
"r2=effective_bnp_taxrate(220)\n",
|
||||||
|
"r3=effective_bnp_taxrate2(220)\n",
|
||||||
|
"print ('net monthly salary paye',gross_salary(220)*(1-r1)/220)\n",
|
||||||
|
"print ('net monthly salary bnp1',gross_salary(220)*(1-r2)/220)\n",
|
||||||
|
"print ('net monthly salary bnp2',gross_salary(220)*(1-r3)/220)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 42,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.4171969377990431"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 42,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"r1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 43,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.5494973397129187"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 43,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"r2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 44,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.48731615081339713"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 44,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"r3"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 48,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"50.0"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 48,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"250/5"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"hello from laptop"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.6.9"
|
||||||
|
},
|
||||||
|
"varInspector": {
|
||||||
|
"cols": {
|
||||||
|
"lenName": 16,
|
||||||
|
"lenType": 16,
|
||||||
|
"lenVar": 40
|
||||||
|
},
|
||||||
|
"kernels_config": {
|
||||||
|
"python": {
|
||||||
|
"delete_cmd_postfix": "",
|
||||||
|
"delete_cmd_prefix": "del ",
|
||||||
|
"library": "var_list.py",
|
||||||
|
"varRefreshCmd": "print(var_dic_list())"
|
||||||
|
},
|
||||||
|
"r": {
|
||||||
|
"delete_cmd_postfix": ") ",
|
||||||
|
"delete_cmd_prefix": "rm(",
|
||||||
|
"library": "var_list.r",
|
||||||
|
"varRefreshCmd": "cat(var_dic_list()) "
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"types_to_exclude": [
|
||||||
|
"module",
|
||||||
|
"function",
|
||||||
|
"builtin_function_or_method",
|
||||||
|
"instance",
|
||||||
|
"_Feature"
|
||||||
|
],
|
||||||
|
"window_display": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
16510
code/misc/python/scripts/textextraction.ipynb
Normal file
16510
code/misc/python/scripts/textextraction.ipynb
Normal file
File diff suppressed because it is too large
Load Diff
309
code/misc/python/scripts/translate.ipynb
Normal file
309
code/misc/python/scripts/translate.ipynb
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"'روباه قهوه ای سریع از روی سگ تنبل پرش می کند.'"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 5,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import translators as ts\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"phrase = 'The quick brown fox jumps over the lazy dog.'\n",
|
||||||
|
"ts.server.google(phrase, from_language='en', to_language='fa')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 57,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from pathlib import Path\n",
|
||||||
|
"fname=Path('/media/dl92/mydata/projects/code/Data')/'faq.pdf'\n",
|
||||||
|
"#fname=Path('/media/dl92/mydata/projects/code/Data')/'Chapter2.pdf'\n",
|
||||||
|
"\n",
|
||||||
|
"import PyPDF2 \n",
|
||||||
|
"\n",
|
||||||
|
"pdfFileObj = open(fname, 'rb')\n",
|
||||||
|
"reader=PyPDF2.PdfReader(pdfFileObj)\n",
|
||||||
|
" \n",
|
||||||
|
"phrase=reader.pages[0].extract_text()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 59,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Frequently asked questions \n",
|
||||||
|
" \n",
|
||||||
|
" Public questions \n",
|
||||||
|
" 1. How can I make my problems without being present? \n",
|
||||||
|
" • In the guide section of the link system called the Relationship with the Agent, the applicant after logging in \n",
|
||||||
|
" The system can receive its problem with the dealership and the duties and through the link \n",
|
||||||
|
" The follow -up by entering the tracking code, see the response from the dealership. \n",
|
||||||
|
" \n",
|
||||||
|
" 2. I have forgotten your fixed password. \n",
|
||||||
|
" • If you have forgotten your fixed passwords you can through this link “your password \n",
|
||||||
|
" I forgot ! “Receive your temporary password by email. \n",
|
||||||
|
" \n",
|
||||||
|
" 3. I don't get a disposable password: \n",
|
||||||
|
" • Preferably use emails other than Yahoo and Gmail.\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"print(ts.server.google(phrase, from_language='fa', to_language='en'))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 20,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"/tmp/ipykernel_31923/3918874040.py:10: DeprecationWarning: The 'text' argument to find()-type methods is deprecated. Use 'string' instead.\n",
|
||||||
|
" texts = str(soup.findAll(text=True)).replace('\\\\n','')\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"import requests\n",
|
||||||
|
"from bs4 import BeautifulSoup\n",
|
||||||
|
"\n",
|
||||||
|
"URL='https://mikhak.mfa.gov.ir/form/landing.xhtml'\n",
|
||||||
|
"page = requests.get(URL)\n",
|
||||||
|
"page.content\n",
|
||||||
|
"\n",
|
||||||
|
"soup = BeautifulSoup(page.content, \"xml\")\n",
|
||||||
|
"soup\n",
|
||||||
|
"texts = str(soup.findAll(text=True)).replace('\\\\n','')\n",
|
||||||
|
"#results=soup.find(id=\"introduction\")\n",
|
||||||
|
"#print(results.prettify())\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 21,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"\"['html', 'Error 403', ' |', 'Forbidden', 'Request blocked by websites firewall due to security reasons!', 'The requested content or URL is incorrect or contains invalid characters.', 'Please review your request and page URL or contact ', 'mikhak.mfa.gov.ir', ' support.', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'Time: 2023-04-21 22:32:42 UTC', '|', 'Error Code: 403', '|', 'Server Code: 2582', '|', 'Domain: mikhak.mfa.gov.ir', '|', 'Your IP: 82.36.108.222', 'خطای ۴۰۳', ' |', 'Forbidden', 'دیواره\\\\u200cی آتش وب\\\\u200cسایت، درخواست شما را به دلایل امنیتی مسدود کرده است.', 'درخواست HTTP خود را بازبینی کنید:', 'محتوای درخواست یا نشانی اینترنتی وارد شده نادرست است، یا کاراکترهای غیرمجاز در آن به کار رفته است.', 'برای اطلاع بیش\\\\u200cتر با پشتیبانی ', 'mikhak.mfa.gov.ir', ' تماس بگیرید.', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'Time: 2023-04-21 22:32:42 UTC', '|', 'Error Code: 403', '|', 'Server Code: 2582', '|', 'Domain: mikhak.mfa.gov.ir', '|', 'Your IP: 82.36.108.222']\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 21,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"texts"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"ename": "ValueError",
|
||||||
|
"evalue": "Language not supported: fa",
|
||||||
|
"output_type": "error",
|
||||||
|
"traceback": [
|
||||||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||||
|
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
|
||||||
|
"Cell \u001b[0;32mIn[1], line 18\u001b[0m\n\u001b[1;32m 12\u001b[0m language \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfa\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;66;03m# Language in which you want to convert\u001b[39;00m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;66;03m#language = 'en'\u001b[39;00m\n\u001b[1;32m 16\u001b[0m \n\u001b[1;32m 17\u001b[0m \u001b[38;5;66;03m# Creating an instance of gTTS\u001b[39;00m\n\u001b[0;32m---> 18\u001b[0m speech \u001b[38;5;241m=\u001b[39m \u001b[43mgTTS\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtext\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtext\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlang\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlanguage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mslow\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 20\u001b[0m \u001b[38;5;66;03m# Saving the converted audio in an mp3 file\u001b[39;00m\n\u001b[1;32m 21\u001b[0m speech\u001b[38;5;241m.\u001b[39msave(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moutput.mp3\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
||||||
|
"File \u001b[0;32m~/Data/projects/code/Python/Envs/General/lib/python3.11/site-packages/gtts/tts.py:150\u001b[0m, in \u001b[0;36mgTTS.__init__\u001b[0;34m(self, text, tld, lang, slow, lang_check, pre_processor_funcs, tokenizer_func, timeout)\u001b[0m\n\u001b[1;32m 148\u001b[0m langs \u001b[38;5;241m=\u001b[39m tts_langs()\n\u001b[1;32m 149\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlang \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m langs:\n\u001b[0;32m--> 150\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLanguage not supported: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m lang)\n\u001b[1;32m 151\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 152\u001b[0m log\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;28mstr\u001b[39m(e), exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
|
||||||
|
"\u001b[0;31mValueError\u001b[0m: Language not supported: fa"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"from gtts import gTTS\n",
|
||||||
|
"import os\n",
|
||||||
|
"\n",
|
||||||
|
"# Text to be converted to speech\n",
|
||||||
|
"text = \"hey big boy? you want some fucky fucky or sucky sucky?\"\n",
|
||||||
|
"#text = \"thats quite alright bitch!\"\n",
|
||||||
|
"\n",
|
||||||
|
"# Farsi text to be converted to speech\n",
|
||||||
|
"#text = \"سلام، حال شما چطور است؟\"\n",
|
||||||
|
"\n",
|
||||||
|
"# Language code for Farsi\n",
|
||||||
|
"language = 'fa'\n",
|
||||||
|
"\n",
|
||||||
|
"# Language in which you want to convert\n",
|
||||||
|
"#language = 'en'\n",
|
||||||
|
"\n",
|
||||||
|
"# Creating an instance of gTTS\n",
|
||||||
|
"speech = gTTS(text=text, lang=language, slow=False)\n",
|
||||||
|
"\n",
|
||||||
|
"# Saving the converted audio in an mp3 file\n",
|
||||||
|
"speech.save(\"output.mp3\")\n",
|
||||||
|
"\n",
|
||||||
|
"# Playing the converted file (optional)\n",
|
||||||
|
"os.system(\"mpg output.mp3\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import pyttsx3\n",
|
||||||
|
"\n",
|
||||||
|
"# Initialize the TTS engine\n",
|
||||||
|
"engine = pyttsx3.init()\n",
|
||||||
|
"\n",
|
||||||
|
"# Farsi text to be converted to speech\n",
|
||||||
|
"text = \"سلام، حال شما چطور است؟\"\n",
|
||||||
|
"\n",
|
||||||
|
"# Set properties (optional)\n",
|
||||||
|
"engine.setProperty('rate', 150) # Speed of speech\n",
|
||||||
|
"engine.setProperty('volume', 1) # Volume (0.0 to 1.0)\n",
|
||||||
|
"\n",
|
||||||
|
"# Convert text to speech\n",
|
||||||
|
"engine.say(text)\n",
|
||||||
|
"\n",
|
||||||
|
"# Save the speech to a file\n",
|
||||||
|
"engine.save_to_file(text, 'output_farsi.mp3')\n",
|
||||||
|
"\n",
|
||||||
|
"# Play the speech\n",
|
||||||
|
"#engine.runAndWait()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 27,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import gtts \n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"pd.Series(gtts.lang.tts_langs()).to_clipboard()\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"\t0\n",
|
||||||
|
"af\tAfrikaans\n",
|
||||||
|
"am\tAmharic\n",
|
||||||
|
"ar\tArabic\n",
|
||||||
|
"bg\tBulgarian\n",
|
||||||
|
"bn\tBengali\n",
|
||||||
|
"bs\tBosnian\n",
|
||||||
|
"ca\tCatalan\n",
|
||||||
|
"cs\tCzech\n",
|
||||||
|
"cy\tWelsh\n",
|
||||||
|
"da\tDanish\n",
|
||||||
|
"de\tGerman\n",
|
||||||
|
"el\tGreek\n",
|
||||||
|
"en\tEnglish\n",
|
||||||
|
"es\tSpanish\n",
|
||||||
|
"et\tEstonian\n",
|
||||||
|
"eu\tBasque\n",
|
||||||
|
"fi\tFinnish\n",
|
||||||
|
"fr\tFrench\n",
|
||||||
|
"gl\tGalician\n",
|
||||||
|
"gu\tGujarati\n",
|
||||||
|
"ha\tHausa\n",
|
||||||
|
"hi\tHindi\n",
|
||||||
|
"hr\tCroatian\n",
|
||||||
|
"hu\tHungarian\n",
|
||||||
|
"id\tIndonesian\n",
|
||||||
|
"is\tIcelandic\n",
|
||||||
|
"it\tItalian\n",
|
||||||
|
"iw\tHebrew\n",
|
||||||
|
"ja\tJapanese\n",
|
||||||
|
"jw\tJavanese\n",
|
||||||
|
"km\tKhmer\n",
|
||||||
|
"kn\tKannada\n",
|
||||||
|
"ko\tKorean\n",
|
||||||
|
"la\tLatin\n",
|
||||||
|
"lt\tLithuanian\n",
|
||||||
|
"lv\tLatvian\n",
|
||||||
|
"ml\tMalayalam\n",
|
||||||
|
"mr\tMarathi\n",
|
||||||
|
"ms\tMalay\n",
|
||||||
|
"my\tMyanmar (Burmese)\n",
|
||||||
|
"ne\tNepali\n",
|
||||||
|
"nl\tDutch\n",
|
||||||
|
"no\tNorwegian\n",
|
||||||
|
"pa\tPunjabi (Gurmukhi)\n",
|
||||||
|
"pl\tPolish\n",
|
||||||
|
"pt\tPortuguese (Brazil)\n",
|
||||||
|
"pt-PT\tPortuguese (Portugal)\n",
|
||||||
|
"ro\tRomanian\n",
|
||||||
|
"ru\tRussian\n",
|
||||||
|
"si\tSinhala\n",
|
||||||
|
"sk\tSlovak\n",
|
||||||
|
"sq\tAlbanian\n",
|
||||||
|
"sr\tSerbian\n",
|
||||||
|
"su\tSundanese\n",
|
||||||
|
"sv\tSwedish\n",
|
||||||
|
"sw\tSwahili\n",
|
||||||
|
"ta\tTamil\n",
|
||||||
|
"te\tTelugu\n",
|
||||||
|
"th\tThai\n",
|
||||||
|
"tl\tFilipino\n",
|
||||||
|
"tr\tTurkish\n",
|
||||||
|
"uk\tUkrainian\n",
|
||||||
|
"ur\tUrdu\n",
|
||||||
|
"vi\tVietnamese\n",
|
||||||
|
"yue\tCantonese\n",
|
||||||
|
"zh-CN\tChinese (Simplified)\n",
|
||||||
|
"zh-TW\tChinese (Mandarin/Taiwan)\n",
|
||||||
|
"zh\tChinese (Mandarin)\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "General",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.11.2"
|
||||||
|
},
|
||||||
|
"orig_nbformat": 4
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user