Skip to content

Instantly share code, notes, and snippets.

View websofter's full-sized avatar
🌴
On vacation

David Amirkhanov websofter

🌴
On vacation
View GitHub Profile
@websofter
websofter / script.js
Created September 24, 2021 12:29
Get file extension in JS
function getFileExtension(filename){
let ext = /^.+\.([^.]+)$/.exec(filename)
return ext == null ? '' : ext[1].length < 5 ? ext[1] : '';
}
@websofter
websofter / README.txt
Last active November 12, 2024 03:13
Python CRON script
CRON starting with cron.py script and it run via tmux demon tool or other.
For example in tmux
$ sudo apt install tmux
$ tmux new-session -s parser
$ source ./venv/bin/activate
$ python cron.py
@websofter
websofter / main.py
Created July 23, 2021 13:44
Convert Python dictionary array to dictionary property array
posts = [
{'name': 'Name 1', 'text': 'Some text 1'},
{'name': 'Name 2', 'text': 'Some text 2'},
{'name': 'Name 3', 'text': 'Some text 3'},
{'name': 'Name 4', 'text': 'Some text 4'}
]
posts_text = []
posts_text = list(map(lambda p: p['text'], posts))
@websofter
websofter / find_date.py
Last active November 12, 2024 03:14
Find Date in any text
import re
import datefinder
def find_date(text):
matches = datefinder.find_dates(text, source=True)
detect_dates=[]
for match in matches:
year = match[0].year
if year > 2010 and year <= datetime.datetime.now().year:
detect_dates.append(match)
@websofter
websofter / parser.py
Created July 21, 2021 15:19
Cross platform selenium parsing with chrome/chromedriver
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
#from fake_useragent import UserAgent
import datetime
import os
import platform
from selenium.common.exceptions import NoSuchElementException, TimeoutException
@websofter
websofter / main.py
Created July 21, 2021 14:42
Search X num digit in text using Python
import re
def get_code(text, length = 8):
pattern= r"\D(\d{%d})\D" % length
code = re.findall(pattern, text)
return code[0]
mail_text = '''
====================================================================================================
@websofter
websofter / .env
Last active November 12, 2024 03:16
Ghost in Docker
# Tag used for the ghost docker image
export GHOST_IMAGE_TAG=latest
# Tag used for the MariaDB docker image
export MARIADB_IMAGE_TAG=latest
# Configure the blog url in ghost
export BLOG_URL=http://127.0.0.1:8022
# Root password used for MariaDB
@websofter
websofter / get_lat_lng.py
Created July 2, 2021 15:10
Convert x,y to lat, long with pyproj
import pyproj
def get_lat_lng(x, y):
#x = 174055.2462
#y = 614374.1559
'''
ISRAEL GEO METADATA get from https://www.expertgps.com/convert-coordinates/
hddd.ddddd° (Lat/Lon Degrees)
hddd° mm.mmm' (Lat/Lon Degrees & Minutes)
hddd° mm' ss.s" (Lat/Lon Deg. Min. Sec.)
@websofter
websofter / main.py
Created July 1, 2021 03:18
Insert bulk data into table in Django/PostgreSQL
def insert_cities(cities):
dbname, tablename = 'MyDB', 'city_coordinates'
with connections[dbname].cursor() as cursor:
for city in cities:
cursor.execute(f"""
INSERT INTO {tablename} (record_id, X, Y, record_id_2, city_id, city_name_heb, secondary_id, city_type_id, city_type_name, cuty_name_eng)
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
(city['record_id'], city['X'], city['Y'], city['record_id_2'], city['city_id'], city['city_name_heb'], city['secondary_id'], city['city_type_id'], city['city_type_name'], city['city_name_eng']))
connections[dbname].commit()
@websofter
websofter / analize.xml
Created July 1, 2021 03:05
Parsing xml data by URL with BeautifulSoup
<esri:Workspace xmlns:esri="http://www.esri.com/schemas/ArcGIS/9.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<WorkspaceDefinition xsi:type="esri:WorkspaceDefinition">
...
</WorkspaceDefinition>
<WorkspaceData xsi:type="esri:WorkspaceData">
<DatasetData xsi:type="esri:TableData">
<DatasetName>city</DatasetName>
<DatasetType>esriDTFeatureClass</DatasetType>