Examples for automating Windows applications via the Microsoft
Component Object Model (COM), Win32API, PythonCOM and other interesting
scripts developed with the Python Windows Extensions from Marc Hammond. If you want to post a script, article or news please use this link Post a Python script. Hint: For sytax highlighting place your code between the tags <pre> and </pre>
This section as RSS feed.
|
|
I had a bunch of filled out word documents with word forms in them and neded them in Excel. initially i tried CSV but it didn't play nice with encodings. So I decided to write directly to XLS. Be first to comment this article |
|
Read more...
|
|
|
This script shows (by web scraping) the number of backlinks which Google found. import datetime, urllib2, re
url='http://google.com/search?' # Set web search URL
hits={'link':'http://www.goermezer.de/'}
# Generate web search term
hits['web search term']=urllib2.quote('link:'+hits['link'])
# Execute web search
urlstr='%sq=%s'%(url,hits['web search term'])
url=urllib2.Request(urlstr)
url.add_header('User-Agent','')
url=urllib2.urlopen(url).read()
# Store date and time of web search
hits['datetimeutc']=datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
# Parse web search results to determine hits
hits['hits']=re.search('Results <b>1</b> - <b>10</b> of about <b>(?P<hits>.+?)</b>',url)
if hits['hits']!=None:
hits['hits']=hits['hits'].group('hits')
hits['hits']=hits['hits'].replace(',','')
hits['hits']=int(hits['hits'])
else:
hits['hits']=0
print hits['hits'] Be first to comment this article |
|
from ctypes.wintypes import windll, c_int, byref, RGB
COLOR_BACKGROUND = 1 # from winuser.h or win32con
SetSysColors = windll.user32.SetSysColors
which_color = RGB(255,0,0) # red
SetSysColors(1, byref(c_int(COLOR_BACKGROUND)), byref(c_int(which_color))) Be first to comment this article |
| |
|
Another script from http://code.activestate.com/recipes/576818/ to create watermarks with images:
import Image, ImageEnhance, os
from os.path import join
def test():
batch("/media/disk/pics", "/home/hasanat/outputfolder/", "/home/hasanat/watermark.png")
def batch(infolder, outfolder, watermark):
mark = Image.open(watermark)
for root, dirs, files in os.walk(infolder):
for name in files: try:
im = Image.open(join(root, name))
if im.mode != 'RGBA':
im = im.convert('RGBA')
layer = Image.new('RGBA', im.size, (0,0,0,0))
position = (im.size[0]-mark.size[0], im.size[1]-mark.size[1])
layer.paste(mark, position)
Image.composite(layer, im, layer).save( join(outfolder, name))
except Exception, (msg):
print msg
if __name__ == '__main__':
test() Be first to comment this article |
|
|
<< Start < Prev 1 2 3 4 5 6 7 8 9 10 Next > End >>
|
| Results 1 - 5 of 84 |