示例#1
0
  def _get(self, path, parse="message", post=False, single=False, **args):
    url = "/".join((API_PREFIX, path))

    request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, self.token,
        http_method=post and "POST" or "GET", http_url=url, parameters=util.compact(args))
    request.sign_request(self.sigmethod, self.consumer, self.token)
    
    if post:
      data = network.Download(request.to_url(), util.compact(args), post).get_json()
    else:
      data = network.Download(request.to_url(), None, post).get_json()

    if isinstance(data, dict) and data.get("errors", 0):
      if "authenticate" in data["errors"][0]["message"]:
        raise exceptions.GwibberServiceError("auth",
            self.account["service"], self.account["username"], data["errors"][0]["message"])
      else:
        for error in data["errors"]:
          log.logger.info("Twitter failure - %s", error["message"])
        return []
    elif isinstance(data, dict) and data.get("error", 0):
      log.logger.error("%s failure - %s", PROTOCOL_INFO["name"], data["error"])
      if "Incorrect signature" in data["error"]:
        print data
        raise exceptions.GwibberServiceError("keyring")
      return []
    elif isinstance(data, str):
      log.logger.error("%s unexpected result - %s", PROTOCOL_INFO["name"], data)
      return []
    
    if parse == "list":
      return [self._list(l) for l in data["lists"]]
    if single: return [getattr(self, "_%s" % parse)(data)]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data]
    else: return []
示例#2
0
  def _get(self, path, parse="message", post=False, single=False, **args):
    url = "/".join((URL_PREFIX, "api", path))
    url += ("&" if "?" in url else "?") + "apikey=%s" % self.account["password"]
    data = network.Download(url, util.compact(args) or None, post).get_json()

    if single: return [getattr(self, "_%s" % parse)(data)]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data]
    else: return []
示例#3
0
    def send(self, message):
        args = {
            "post_method": "microblog",
            "user_app_key": self.account["secret_key"],
            "api_key": API_KEY,
            "body": message,
        }

        data = network.Download("http://api.ping.fm/v1/user.post", util.compact(args), post=True)
        return []
示例#4
0
def parsePage(path):
    pathList = path.split('/')

    if len(pathList) < 2:
        print 'Invalid URL'
        return None

    typeString = pathList[1]

    soup = getSoupFromPath(path)

    h1Title = soup.find('h1')
    if h1Title is None:
        return None
    title = unicode(h1Title.string)

    metadataDiv = soup.find(class_='game-preview')
    if metadataDiv is None:
        print 'No main content present in page'
        return None

    # Get metadata
    rating = parseRating(metadataDiv)

    metadataList = compact([
        parseMetadataTableRow(row)
        for row in metadataDiv.find(class_='descr').find_all('tr')
    ])
    metadata = dict(metadataList)

    downloads = compact([
        parseDownloadRow(row)
        for row in metadataDiv.find_all(class_='download')
    ])

    manuals = [
        parseManualRow(row) for row in metadataDiv.find_all(class_='manual')
    ]

    descriptionAndCompatability = parseDescriptionAndCompatability(soup)

    return buildEntry(path, typeString, title, rating, metadata, downloads,
                      manuals, descriptionAndCompatability)
示例#5
0
    def send(self, message):
        args = {
            "post_method": "microblog",
            "user_app_key": self.account["secret_key"],
            "api_key": API_KEY,
            "body": message
        }

        data = network.Download("http://api.ping.fm/v1/user.post",
                                util.compact(args),
                                post=True)
        return []
示例#6
0
 def joinComplete(self, result):
     """Complete the DHT join process and determine our download information.
     
     Called by the DHT when the join has been completed with information
     on the external IP address and port of this peer.
     """
     my_addr = findMyIPAddr(result,
                            config.getint(config.get('DEFAULT', 'DHT'), 'PORT'),
                            config.getboolean('DEFAULT', 'LOCAL_OK'))
     if not my_addr:
         raise RuntimeError, "IP address for this machine could not be found"
     self.my_contact = compact(my_addr, config.getint('DEFAULT', 'PORT'))
     if not self.nextRefresh or not self.nextRefresh.active():
         self.nextRefresh = reactor.callLater(60, self.refreshFiles)
     return (my_addr, config.getint('DEFAULT', 'PORT'))
示例#7
0
  def _get(self, path, post=False, parse="message", kind="entries", single=False, **args):
    url = "/".join((URL_PREFIX, path))
    data = network.Download(url, util.compact(args), post,
        self.account["username"], self.account["secret_key"]).get_json()

    if isinstance(data, dict) and data.get("errorCode", 0):
      if "unauthorized" in data["errorCode"]:
        raise exceptions.GwibberServiceError("auth", self.account["service"], self.account["username"], data["errorCode"])
   
    if single: return [getattr(self, "_%s" % parse)(data)]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data["entries"]]
    else: return []

    if parse:
      data = data[kind][0] if single else data[kind]
      return [getattr(self, "_%s" % parse)(m) for m in data]
示例#8
0
	def _get(self, path, parse="message", post=False, single=False, **args):
		url = "/".join((API_PREFIX, path))
		data = network.Download(url, util.compact(args), post, self.account["username"], self.account["password"]).get_json()
		if isinstance(data, dict) and data.get("error", 0):
			if "authenticate" in data["error"]:
				raise exceptions.GwibberServiceError("auth", self.account["service"], self.account["username"], data["error"])
		elif isinstance(data, dict) and data.get("error", 0):
			log.logger.error("%s failure - %s", PROTOCOL_INFO["name"], data["error"])
			return []
		elif isinstance(data, str):
			log.logger.error("%s unexpected result - %s", PROTOCOL_INFO["name"], data)
			return []

		if single: return [getattr(self, "_%s" % parse)(data)]
		if parse: return [getattr(self, "_%s" % parse)(m) for m in data]
		else: return []
示例#9
0
文件: buzz.py 项目: SMIDEC/gwibber-lc
  def _get(self, path, collection="items", parse="message", post=False, single=False, body=None, **args):
    url = "/".join((URL_PREFIX, path))
    args.update({"alt": "json"})
    
    request = oauth.OAuthRequest.from_consumer_and_token(self.consumer, self.token,
        http_method=post and "POST" or "GET", http_url=url, parameters=util.compact(args))
    request.sign_request(self.sigmethod, self.consumer, self.token)

    data = network.Download(request.to_url(), None, post,
        header=["Content-Type: application/json"] if body else None, body=body)
    
    data = data.get_json()

    if single: return [getattr(self, "_%s" % parse)(data["data"])]
    if parse: return [getattr(self, "_%s" % parse)(m) for m in data["data"][collection]]
    else: return []
示例#10
0
文件: digg.py 项目: SMIDEC/gwibber-lc
    def _get(self, path, parse="story", post=False, single=False, **args):
        url = "/".join((URL_PREFIX, path)) + "?appkey=http://gwibber.com&type=json"

        data = network.Download(url, util.compact(args) or None, post).get_json()

        if not data:
            return []

        if "stories" in data:
            if single:
                return [getattr(self, "_%s" % parse)(data["stories"])]
            if parse:
                return [getattr(self, "_%s" % parse)(m) for m in data["stories"]]
            else:
                return []
        else:
            if ("status" in data) and ("message" in data):
                print "Digg: got message with status %s and message %s" % (data["status"], data["message"])
            return []
示例#11
0
  def PerformOp(self, opdata):
    try: o = json.loads(opdata)
    except: return
    
    logger.debug("** Starting Single Operation **")
    self.LoadingStarted()
    
    params = ["account", "operation", "args", "transient"]
    operation = None
    
    if "account" in o and self.collector.get_account(o["account"]):
      account = self.collector.get_account(o["account"])
    
    if "id" in o:
      operation = self.collector.get_operation_by_id(o["id"])
    elif "operation" in o and self.collector.validate_operation(account, o["operation"]):
        operation = util.compact([(account, o["operation"], o["args"], None)])

    if operation:
      self.perform_async_operation(operation)
示例#12
0
 def contactInfo(self):
     """Get the compact contact info for the node."""
     if self._contactInfo is None:
         self._contactInfo = compact(self.id, self.host, self.port)
     return self._contactInfo
示例#13
0
 def send(self, operations):
   operations = util.compact(operations)
   if operations:
     self.LoadingStarted()
     logger.debug("*** Sending Message ***")
     self.perform_async_operation(operations)
示例#14
0
 def _search(self, **args):
   data = network.Download("%s/api/search.json" % self.url_prefix, util.compact(args))
   data = data.get_json()["results"]
   return [self._result(m) for m in data]
示例#15
0
  def _search(self, **args):
    data = network.Download("%s/api/search.json" % URL_PREFIX, util.compact(args))
    data = data.get_json()

    return [self._result(m) for m in data["results"]]
示例#16
0
  def _search(self, **args):
    data = network.Download("http://search.twitter.com/search.json", util.compact(args))
    data = data.get_json()["results"]

    return [self._result(m) for m in data]