Skip to content

Instantly share code, notes, and snippets.

View scionoftech's full-sized avatar

Sai Kumar Yava scionoftech

  • Hyderabad, India
View GitHub Profile
@scionoftech
scionoftech / watchdog_sample.py
Created June 13, 2019 13:25
this is a python script to mointor a folder for changes
import time
import os
import shutil
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class StartMonitor(FileSystemEventHandler):
def __init__(self, monitor_path, move_path):
@scionoftech
scionoftech / image_read.py
Created June 14, 2019 07:09
This is a python script to read text from image using tesseract ocr
from PIL import Image
import numpy as np
import pytesseract
# pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe"
original = Image.open(IMAGE_PATH)
#original.show()
img = np.array(original)
@scionoftech
scionoftech / pdf_form_reader.py
Last active June 14, 2019 07:28
this is a python script for reading pdf forms
import json
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdftypes import resolve1
fp = open(PDF_FILE_PATH, 'rb')
parser = PDFParser(fp)
doc = PDFDocument(parser)
print(doc)
@scionoftech
scionoftech / pdf2excel.py
Last active June 14, 2019 07:39
this is a python script to extract tables from pdf and convert to excel
import click
from pathlib import Path
import pdfplumber
import pandas as pd
from pandas import ExcelWriter
def to_excel(path, output_path):
with pdfplumber.open(path) as pdf:
data = []
@scionoftech
scionoftech / Send_Email_Python
Created July 31, 2019 12:07
A simple python script to send email
import smtplib
"""
SMTP Server Information
1. Gmail.com: smtp.gmail.com:587
2. Outlook.com: smtp-mail.outlook.com:587
3. Office 365: outlook.office365.com
Please verify your SMTP settings info.
"""
FROM = "YOUR EMAIL ID"
@scionoftech
scionoftech / How to publish python packages to pypi
Created August 20, 2019 18:57
How to publish python packages to pypi
# this will create archive files
python setup.py sdist
# install twine
pip install twine
# https://test.pypi.org
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
# https://pypi.org
twine upload dist/*
@scionoftech
scionoftech / roundrobinmatches.py
Created August 23, 2019 08:07
This a python script for generating roundrobin matches for sporting events
from itertools import combinations
from operator import itemgetter
def getroundrobinmatches(participants):
rounds = participants-1 if participants%2 == 0 else participants
data = list(range(1,participants+1))
comb = combinations(data, 2)
@scionoftech
scionoftech / sporting macthes elimination formulas
Created September 1, 2019 07:17
This gist is for round robin and Single Eliminaiton rules formulas
***** round robin macthes *****
(Even number participants)
----------
n = no of participants
matches = n(n-1)/2
rounds = n-1
byes = 0
Eg.
participants = 10
@scionoftech
scionoftech / rotate_upside_down_text_image.py
Created September 10, 2019 13:12
This python script rotates upside down text image to proper image
from PIL import Image as pillowimg
import numpy as np
import cv2
import pytesseract
# PIL image
def check_orientation(img):
newdata = pytesseract.image_to_osd(np.array(img))
orgi_orientation = re.search('(?<=Rotate: )\d+', newdata).group(0)
# check image orientation
if orgi_orientation != 0:
@scionoftech
scionoftech / GetWiki.py
Last active June 9, 2024 21:33
A small Python Code to get Wikipedia page content in plan text
# https://en.wikipedia.org/wiki/Python_(programming_language)
# https://www.mediawiki.org/wiki/API:Main_page
# 1. Get a plain text representation of either the entire page or the page "extract" straight from the API with the extracts prop
# Note that this approach only works on MediaWiki sites with the TextExtracts extension. This notably includes Wikipedia, but not some smaller Mediawiki sites like, say, http://www.wikia.com/
# You want to hit a URL like
# https://en.wikipedia.org/w/api.php?action=query&format=json&titles=Bla_Bla_Bla&prop=extracts&exintro&explaintext