Skip to content

Instantly share code, notes, and snippets.

@haradreborn
haradreborn / timeout_exception.py
Last active August 29, 2015 14:07
Timeout exception with traceback. Works only on linux!
import signal
from functools import wraps
import errno
import os
import time
import traceback
'''
Usage example:
@haradreborn
haradreborn / send_email.py
Created October 16, 2014 06:28
Email sending with gmail smtp
import smtplib
def sendemail(from_addr, to_addr_list, cc_addr_list,
subject, message,
login, password,
smtpserver='smtp.gmail.com:587'):
header = 'From: %s\n' % from_addr
header += 'To: %s\n' % ','.join(to_addr_list)
header += 'Cc: %s\n' % ','.join(cc_addr_list)
@haradreborn
haradreborn / paint_kivi.py
Created October 16, 2014 06:30
Kivi paint app example
from random import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.graphics import Color, Ellipse, Line
class MyPaintWidget(Widget):
def on_touch_down(self, touch):
@haradreborn
haradreborn / chrome_locators.py
Last active December 13, 2017 22:34
Chromedriver examples with locators
import os
from selenium import webdriver
import selenium.webdriver.support.ui as ui
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
chromedriver = "D:\\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
@haradreborn
haradreborn / rename_file.py
Last active August 29, 2015 14:07
Rename file
#!/usr/bin/env python
from os import rename, listdir
badprefix = "prefix_"
fnames = listdir('C:\\Users\\User\\Downloads')
dir = "C:\\Users\\User\\Downloads"
for fname in fnames:
#print(fname)
if fname.startswith(badprefix):
@haradreborn
haradreborn / unit_test.py
Created October 16, 2014 08:06
Selenium unittest example structure
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
import os
chromedriver = "D:\\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
class CS(unittest.TestCase):
@haradreborn
haradreborn / culebra.py
Created October 16, 2014 08:08
Culebra paint
print (" __ __ __ __ ")
print (" / \ / \ / \ / \ ")
print ("________/ __\/ __\/ __\/ __\__________")
print ("_______/ /__/ /__/ /__/ /_____________")
print (" | / \ / \ / \ / \ \___ ")
print (" |/ \_/ \_/ \_/ \ o \ ")
print (" \_____/--< ")
@haradreborn
haradreborn / excel_print.py
Created October 16, 2014 11:36
Print data from excel
#!/usr/bin/env python
from os import rename, listdir
import xlrd
rb = xlrd.open_workbook('C:\\Users\\IEUser\\Downloads\\test.xlsx',formatting_info=False)
sheet = rb.sheet_by_index(0)
for rownum in range(sheet.nrows):
row = sheet.row_values(rownum)
for c_el in row:
if type(c_el) is float:
@haradreborn
haradreborn / ie_download.py
Last active August 29, 2015 14:07
IE file download automation with pywin
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Ie()
driver.get("https://www.download.com")
print("download")
driver.set_page_load_timeout(10)
try:
@haradreborn
haradreborn / get_from_csv.py
Created October 29, 2014 11:01
Get selected columns from csv file
def csv_get_image(self, file):
image_arr = []
fi = open(file, 'rb')
data = fi.read()
fi.close()
fo = open(file, 'wb')
fo.write(data.replace('\x00', ''))
#fo.write(data.replace('0xff', ''))
fo.close()