Last active
August 29, 2015 14:06
-
-
Save yekm/59686a4f262ad3ea9571 to your computer and use it in GitHub Desktop.
pastebin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2, sys | |
import numpy | |
image = cv2.imread(sys.argv[1]) | |
image = image[318:812,468:1156,:] | |
template = cv2.imread(sys.argv[2]) | |
#template = image[30:40,30:40,:] | |
#cv2.imshow('image', image) | |
result = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED) | |
#cv2.imshow('res', result) | |
nimg = numpy.asarray(result) | |
amax = numpy.amax(nimg) | |
argmax = numpy.argmax(nimg) | |
x,y = numpy.unravel_index(argmax, nimg.shape) | |
#print "amax {}".format(amax) | |
#print "argmax {}".format(argmax) | |
#print "shape {}".format(nimg.shape) | |
#print "x,y {} {}".format(x, y) | |
if amax < 0.6: | |
exit(-1) | |
print "{} {}".format(y+468, x+318) | |
#val, result = cv2.threshold(result, amax-0.05, 255, cv2.THRESH_BINARY) | |
#cv2.imshow('threshold', result) | |
#print result.shape | |
#nimg = numpy.asarray(result) | |
#ii = numpy.argwhere(nimg == 255) | |
#print "{} {}".format(ii[0][1]+468, ii[0][0]+318) | |
#else: | |
# exit(-1) | |
#while cv2.waitKey(33) != ord('q'): | |
# True | |
#cv2.destroyAllWindows() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -i | |
while true; do | |
cat <<EOF | |
l -- list file names in current directory | |
c -- bring up calculator | |
f -- sign off this session | |
d -- display the time and date | |
b -- background job (See Note 1 below) | |
s -- interactive shell (See Note 2 below) | |
q -- quit | |
pick something: | |
EOF | |
read opt | |
case "$opt" in | |
l) | |
echo "Listing files in current directory:" | |
ls -la | |
;; | |
c) | |
echo "A calculator. Type something like 2+3 and hit enter. Then done hit Ctrl+d:" | |
bc | |
;; | |
f) | |
echo "siging off..." | |
sleep 2 | |
# this would not work since we are not a login shell | |
logout | |
;; | |
d) | |
echo "time and date" | |
date | |
;; | |
b) | |
echo "running some bg job" | |
sleep 100 &>/dev/null & | |
;; | |
s) | |
echo "running interactive shell" | |
bash -i | |
;; | |
q) | |
echo "quitting" | |
sleep 2 | |
exit 0 | |
;; | |
esac | |
echo "waiting before clearing the screen..." | |
sleep 3 | |
clear | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os, time, datetime, re | |
import praw | |
import saxo | |
subreddit_r = re.compile('[a-z0-9]+') | |
@saxo.command() | |
def r(arg): | |
if not arg: | |
return "Fetch links from reddit" | |
if not saxo.env("base"): | |
return "Sorry, this command requires an IRC instance" | |
if not subreddit_r.match(arg): | |
return "Sorry, subreddit name must match " + subreddit_r.pattern | |
sname = arg | |
path = os.path.join(saxo.env("base"), "database.sqlite3") | |
with saxo.database(path) as db: | |
c = db.connection.cursor() | |
if not "reddit_stat" in db: | |
db['reddit_stat'].create(("name", "text unique"), ("value", str)) | |
tname = "reddit_%s" % sname | |
if not tname in db: | |
db[tname].create(('url', 'text unique'), ('req_by', str)) | |
url = c.execute("select url from %s where req_by = ''" % tname).fetchone() | |
if url == None: | |
rtime = c.execute("select value from reddit_stat where name = ?", [tname]).fetchone() | |
if rtime != None and rtime[0] == str(datetime.date.today()): | |
return "No more %s for today" % sname | |
reddit = praw.Reddit(user_agent='irc_pic_bot') | |
s = reddit.get_subreddit(sname).get_hot(limit=32) | |
for x in s: | |
if x.url.endswith(('.jpg', '.jpeg', '.gif', '.png')): | |
c.execute("replace into %s values(?, '')" % tname, [x.url]) | |
db.commit() | |
c.execute("replace into reddit_stat values (?, ?)", [tname, str(datetime.date.today())]) | |
db.commit() | |
url = c.execute("select url from %s where req_by = ''" % tname).fetchone() | |
if url == None: | |
return "No more urls. Maybe reddit is down." | |
c.execute("replace into %s values (?, ?)" % tname, [url[0], saxo.env("nick")]) | |
db.commit() | |
return url[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment