Skip to content

Instantly share code, notes, and snippets.

@cra
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save cra/01cc8e1201c87544aa29 to your computer and use it in GitHub Desktop.

Select an option

Save cra/01cc8e1201c87544aa29 to your computer and use it in GitHub Desktop.
#!/usr/bin/python2
# coding: utf-8
import webbrowser
import urllib2
import time
FILENAME = "satana.dat"
GDE_ISKAT_TO_BLYAT = "gde_iskat_to_blyat.dat"
WAIT_AFTER_EACH = 1
WAIT_FOR_SECS = 10
# Format: "DD.MM.YYYY"
DATE_FROM = "01.01.2014"
DATE_TILL = "01.06.2014"
SKIP = 3
DEBUG = False
# Uncomment to print instead of browser open
#DEBUG = True
class WaitCounter(object):
value = 0
total_counter = 0
def __init__(self, each, delay):
self.each = each
self.delay = delay
print u"Waiting for %ss after each %s counts" % (self.delay, self.each)
def tweak(self, need_delay=True):
if need_delay:
self.value += 1
if (self.value % self.each) == 0:
self.value = 0
time.sleep(self.delay)
self.total_counter += 1
line = "Counter:" if need_delay else "(Skipped) Counter:"
print line, self.total_counter
def wait(self):
print "Time to wait. Sleeping for %ss" % self.delay
time.sleep(self.delay)
def open_browser_suka(link):
if DEBUG:
print link
else:
webbrowser.open_new_tab(link)
def prepare_link(input_line, search_site):
website = u"http://google.com"
input_line = urllib2.quote(input_line)
query = u"+".join([u"%s" % x for x in input_line.split()])
dates_tag = u"&tbs=cdr%%3A1%%2Ccd_min%%3A%s%%2Ccd_max%%3A%s" \
% (DATE_FROM, DATE_TILL)
return u"http://google.com/search?%s&q=site%%3A%s+%s" % (dates_tag, search_site, query)
def get_search_list(filename):
search_list = []
with open(filename, "r") as fp:
for line in fp.readlines():
search_list += [line[:-1]]
return search_list
if __name__ == "__main__":
counter = WaitCounter(WAIT_AFTER_EACH, WAIT_FOR_SECS)
search_list = get_search_list(GDE_ISKAT_TO_BLYAT)
print "Using '%s' as input file for search tags" % FILENAME
print "Using the following search sites (from '%s'):" % GDE_ISKAT_TO_BLYAT
print "\n".join(search_list)
with open(FILENAME, "r") as fp:
for line in fp.readlines():
if len(line.strip()) > 0:
for s in search_list:
noskip = counter.total_counter > SKIP
if noskip:
prepared_link = prepare_link("\"%s\"" % line, s)
open_browser_suka(prepared_link)
counter.tweak(noskip)
else:
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment