示例#1
0
 def saveConfig(self, config, fname=None):
     if not fname:
         fname = self.conf_file
     f = open(fname, "w")
     Location.getJsonModule().dump(config, f, indent=2)
     f.write("\n")  # json doesn't include a trailing newline?
     f.close()
示例#2
0
def main():
    
    try:

        Experiment.initLogging(os.environ.has_key("GATEWAY_INTERFACE"))
        
        if os.environ.has_key("GATEWAY_INTERFACE"):
            # CGI
            (odict, args) = getCGIOptions()
        else:
            # Command line.  All the output is still CGI-ish, though.  Sorry.
            (odict, args) = getOptions()
        (odict, args) = processOptions(odict, args)
            
        data = newCreature(odict, odict["e"], odict.get("p"))
        data = Location.getJsonModule().dumps(data, indent=2)
        
        print "Content-type: application/json"
        print "Content-length: %s" % (len(data))
        print
        print data

    except:
        msg = string.join(apply( traceback.format_exception, sys.exc_info() ), "")
        if (msg[-1] == "\n"):
            msg = msg[:-1]
        logging.getLogger().warning(msg)
        data = "Huh?\n%s" % (msg)
        print "Status: 500 Internal Server Error"
        print "Content-type: text/plain"
        print "Content-length: %s" % (len(data))
        print
        print data
示例#3
0
 def loadConfig(self, fname=None):
     if not fname:
         fname = self.conf_file
     f = open(fname)
     config = Location.getJsonModule().load(f)
     f.close()
     if config.get("debug"):
         logging.getLogger().setLevel(logging.DEBUG) # Set the root level.
     return config
示例#4
0
def tweet(odict, creature):
    
    logger = logging.getLogger()
    logger.info("Posting %s as %s..." % (creature.getImagePath(), creature.getFullPageURL()))
    creds = Location.getJsonModule().load(open(Location.getInstance().toAbsolutePath(".twitter.json")))
    twitter = Twython(creds["app"], creds["app_secret"], creds["token"], creds["token_secret"])
    photo = open(creature.getImagePath(), 'rb')
    if (not odict.get("no-op", False)):
        response = twitter.upload_media(media=photo)
        response = twitter.update_status(status=creature.getFullPageURL(), media_ids=[response['media_id']])
        logger.info("Posted as %s." % (response["id_str"]))