Created
July 5, 2016 20:19
-
-
Save kjmancuso/a40f4d5e47b6f768a7bf5032420b28f2 to your computer and use it in GitHub Desktop.
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
#!/home/kevin/.virtualenvs/ptp/bin/python | |
import sys | |
import MySQLdb as mdb | |
import requests | |
cursor_file = sys.path[0] + '/movie_cursor.txt' | |
DB_HOST = 'kodi' | |
DB_USER = 'kodi' | |
DB_PASS = 'kodi' | |
DB_NAME = 'MyVideos99' | |
db = mdb.connect(host=DB_HOST, user=DB_USER, passwd=DB_PASS, db=DB_NAME) | |
def get_movies(mid=False): | |
query = ('SELECT idMovie AS id, c00 AS title, c07 AS year, c09 AS imdb' | |
' FROM movie') | |
if mid: | |
query = query + ' WHERE idMovie > %s' % mid | |
cur = db.cursor() | |
cur.execute(query) | |
return cur.fetchall() | |
def get_cursor(): | |
with open(cursor_file, 'r') as fp: | |
cursor = fp.read() | |
return cursor | |
def update_cursor(id): | |
with open(cursor_file, 'w') as fp: | |
fp.write(str(id)) | |
return | |
def announce(title, year, imdb): | |
URL = 'http://redacted' | |
msg = ('SneakerNet New Movie Added [orion] - %s - %s - ' | |
'http://www.imdb.com/title/%s' % (title, year, imdb)) | |
payload = {'chan': '#redacted', | |
'msg': msg} | |
r = requests.post(URL, data=payload) | |
return r | |
def main(): | |
cursor = get_cursor() | |
movies = get_movies(cursor) | |
if len(movies) == 0: | |
return False | |
for id, title, year, imdb in movies: | |
announce(title, year, imdb) | |
update_cursor(id) | |
return | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment