Skip to content

Instantly share code, notes, and snippets.

@feltnerm
Created April 19, 2011 05:49
Show Gist options
  • Save feltnerm/926879 to your computer and use it in GitHub Desktop.
Save feltnerm/926879 to your computer and use it in GitHub Desktop.
simple motivational quotes on your console.
#!/usr/bin/env python
# Every hour:
# 1. Open quotes or goals based on the one opened least frequently
# a. Return random line from file
# b. display file
import time
import random
def get_line(lines):
# pick random line
# parse it by separating the ';'
# restructure it in quote format
num_lines = len(lines)
rand_line = random.randint(0, num_lines - 1)
line = lines[rand_line]
if '+' in line:
t = line.split('+')
line = t[0]
author = t[1]
if t[1] == None:
author = "Anon."
else:
author = t[1]
new_string = """'%s' -%s""" % (line, author)
print new_string.strip()
else:
print line
def get_motivation():
# decide which type of motivation
r = random.randint(0, 1)
if r == 0:
try:
f = open('/Users/mark/.geeklets/quotes.txt', 'r')
l = f.readlines()
f.close()
get_line(l)
except:
print 'File not accessible or found.'
else:
try:
f = open('/Users/mark/.geeklets/goals.txt', 'r')
l = f.readlines()
f.close()
get_line(l)
except:
print 'File not accessible or found.'
get_motivation()
'''
START_TIME = time.mktime(time.localtime())
while 1:
CURRENT_TIME = time.mktime(time.localtime())
time_difference = CURRENT_TIME - START_TIME
# print time_difference
if time_difference >= 5: # number of seconds in 1 hour
get_motivation()
START_TIME = time.mktime(time.localtime())
else:
continue
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment