Esempio n. 1
0
    def get(self):
        self.response.out.write('<html><body>')

        app_status = status.load()

        since_id = app_status.get('reply_since_id', -1)

        if since_id:
            mentions = twitter.get_mentions(since_id)
        else:
            mentions = twitter.get_mentions()

        self.response.out.write("<pre>" + str(since_id) + ":" + str(mentions) + "</pre>")

        if not mentions:
            return

        for mention in reversed(mentions):
            self.response.out.write("<p>" + str(mention['id']) + " | " + mention['user']['screen_name'] + " protected("+ str(mention['user']['protected']) + "): " + mention['text'] +"</p>")

        self.reply_to_user(mentions[-1]['user'], app_status)

        twitter.follow_user(mentions[-1]['user']['screen_name'])
        app_status['reply_since_id'] = mentions[-1]['id']
        app_status['latest_user_replied_to'] = mentions[-1]['user']['screen_name']

        status.save(app_status)

        self.response.out.write('</body></html>')
Esempio n. 2
0
    def get(self):

        app_status = status.load()

        # Just get the latest tweets
        tweets = twitter.get_timeline_tweets(800)
        tweets = filter_tweets(tweets)
        tweets = filter(lambda t:not t['user']['screen_name'] == twitter_settings.screen_name, tweets)

        if len(tweets) <= 1:
            self.response.out.write('<p>Could not generate tweet (not enough eligible tweets)</p>')
            app_status['latest_tweet'] = 'Could not generate tweet (not enough eligible tweets)'
            return

        recent_tweets = twitter.get_tweets(twitter_settings.screen_name, True)

        best_tweet = create_markovated_tweet(tweets, 140, map(lambda t: t['text'].strip(), recent_tweets))

        if best_tweet != None:
            twitter.post_tweet(best_tweet)
            self.response.out.write('<p>' + best_tweet + '</p>' + '(' + str(len(best_tweet)) + ')')
            app_status['latest_tweet'] =  best_tweet;
        else:
            self.response.out.write('<p>Could not generate tweet</p>')
            app_status['latest_tweet'] = 'Could not generate tweet'
            
        status.save(app_status)
Esempio n. 3
0
def getModel(dateWatering='UNK', wasWet='UNK', isWetNow='UNK', statusMessage = "UNK"):
    status.load()
    viewModel = {
        'auto': "ON" if status.auto else "OFF",
        'dateWatering': status.last_watering.strftime("%x %X"),
        'wasWet': mgr.get_wet_dry(status.soil_was_wet_after),
        'isWet': mgr.get_wet_dry(mgr.checkIsWet()),
        'log': readLog(),
        'history': readHistory(),
        'events': [],
        'status': status.status,
        'title': 'WWWater @{0}'.format(datetime.datetime.now()),
        'day': (datetime.datetime.today()-datetime.timedelta(days=1)).day,
        'month':(datetime.datetime.today()-datetime.timedelta(days=1)).month,
        'year':(datetime.datetime.today()-datetime.timedelta(days=1)).year,
    }
    return viewModel
Esempio n. 4
0
def doWork():
    status.load()
    try:
        autoIsOn = status.auto
        isWet = checkIsWet()
        sw = shouldWork(isWet)
        s = "AUTO: {0}; SOIL: {1}; SHOULD_WORK: {2}".format(autoIsOn, get_wet_dry(isWet), sw)
        writeLog(s, "INFO" if isWet else "WARN")
        if sw:
            writeLog("Start watering.", "INFO")
            feed()
            isWet = checkIsWet()
            status.last_watering = datetime.datetime.now()
            status.soil_was_wet_after = isWet
            status.save()
            writeLog("After watering the soil is {0}.".format(get_wet_dry(isWet)), "INFO" if isWet else "ERROR")
    except KeyboardInterrupt:
        writeLog("Cleanup GPIO ports", "INFO")
        GPIO.cleanup()
        status.status = "SLEEPING"
        status.save()
Esempio n. 5
0
        if has_mark(rev):
            print >> sys.stderr, "Already having commit '%s'" % rev
        else:
            print >> sys.stderr, "Going to import revision ", rev
            fast_import(ops, parse_revision(ops, rev))
        

if __name__ == "__main__":
    import optparse
    parser = optparse.OptionParser()
    parser.add_option("-d", "--db", dest="database",
                      help="The monotone database to use")
    parser.add_option("-m", "--marks", dest="marks", default="mtn2git-marks",
                      help="The marks allocated by the mtn2git command")
    parser.add_option("-t", "--mtn", dest="mtn", default="mtn",
                      help="The name of the mtn command to use")
    parser.add_option("-s", "--status", dest="status", default="mtn2git.status.v2",
                      help="The status file as used by %prog")
    parser.add_option("-r", "--revision", dest="rev", default=None,
                      help="Import a single revision to help debugging.")

    (options,_) = parser.parse_args(sys.argv)
    status.mark_file = file(options.marks, "a")

    try:
        status.load(options.status)
    except IOError:
        print >> sys.stderr, "Failed to open the status file"
    main(options.mtn, options.database, options.rev)
    status.store(options.status)
Esempio n. 6
0
def main(argv):
	global child_process
	os.environ["LD_LIBRARY_PATH"] = os.environ.get("LD_LIBRARY_PATH", "")+":"+os.getcwd()+"/contrib/lib"
	signal.signal(signal.SIGINT, cleanup)
	signal.signal(signal.SIGQUIT, cleanup)
	if s.status == None:	
		try:
			maxFrames = int(argv[2])
		except:
			maxFrames = -1
		try:
			direct = str(argv[1])
		except:
			direct = None
		s.status = {
			"directory" : direct,
			"pid" : os.getpid(),
			"maxFrames" : maxFrames,
			"currentFrame" : 0,
			"timestamp" : int(datetime.datetime.now().strftime("%s"))
		}
		s.save()
	
	
	try:
		if s.status["directory"][-1] == '/':
			s.status["directory"] = s.status["directory"][0:-1]
	except:
		s.status["directory"] = "data/"+datetime.datetime.now().strftime("%F/%H:%M")
		
	if not os.path.exists(s.status["directory"]):
		os.makedirs(s.status["directory"])
	with open(s.status["directory"]+"/experiment", "w") as f:
		f.write("Running")
		
	s.status["pid"] = os.getpid()
	s.status["currentFrame"] = 0
	s.save()
	lasttime = float(datetime.datetime.now().strftime("%s.%f"))
	initialFiles = len([f for f in os.listdir("data") if 'png' in f])
	maxFrames = int(s.status["maxFrames"])
	while (s.status != None and (s.status["maxFrames"] < 0 or s.status["currentFrame"] < s.status["maxFrames"])):
		s.load()
		#error = subprocess.call(["./FLIRA65-Capture", "-f", "-1", "-D", s.status["directory"]])
		child_process = subprocess.Popen(["./FLIRA65-Capture", "-f", str(maxFrames), "-D", s.status["directory"], '-F', s.status["bitdepth"], '-T', s.status["period"]])
		while child_process.poll() is None:
			time.sleep(1)
			files = [f for f in os.listdir("data") if 'png' in f]
			s.status["currentFrame"] = len(files)-initialFiles
			if len(files) == 0:
				continue
			latest = s.status["directory"]+"/"+files[-1]
			s.status["lastFrame"] = "<a href='%s'>%s</a>" % (s.status["directory"]+"/"+files[-1], files[-1])
			s.save()

		if (maxFrames > 0):
			maxFrames = maxFrames-s.status["currentFrame"]
		s.save()
		pass
		
	cleanup(None,None)
	return 0 # redundant
Esempio n. 7
0
    parser.add_option("-m",
                      "--marks",
                      dest="marks",
                      default="mtn2git-marks",
                      help="The marks allocated by the mtn2git command")
    parser.add_option("-t",
                      "--mtn",
                      dest="mtn",
                      default="mtn",
                      help="The name of the mtn command to use")
    parser.add_option("-s",
                      "--status",
                      dest="status",
                      default="mtn2git.status.v2",
                      help="The status file as used by %prog")
    parser.add_option("-r",
                      "--revision",
                      dest="rev",
                      default=None,
                      help="Import a single revision to help debugging.")

    (options, _) = parser.parse_args(sys.argv)
    status.mark_file = file(options.marks, "a")

    try:
        status.load(options.status)
    except IOError:
        print >> sys.stderr, "Failed to open the status file"
    main(options.mtn, options.database, options.rev)
    status.store(options.status)