示例#1
0
def store_newest_downloads(update_credentials):
    download_links = dict()
    credentials = credentials_module.get_credential()

    if update_credentials == credentials:
        rsapi = RapidShareAPI(credentials=credentials) #folderid="6834"
        download_links["Rapidshare"] = rsapi.get_download_links(fields="filename,size,uploadtime")

        hfapi = HotFileAPI(credentials=credentials)
        download_links["Hotfile"] = hfapi.get_download_links(folderid="1701142", hashid="2e37c99")

        result = {}

        for hoster, downloads in download_links.iteritems():
            for properties in downloads.itervalues():
                try:
                    # Convert time string into a more readable form:
                    properties["date"] = time.ctime(float(properties["uploadtime"]))
                except KeyError:
                    pass

                properties["version"] = None

                try:
                    version_string = re.search(r'diribeowin32_([\w].*).zip', properties["filename"]).group(1)
                    properties["version"] = string_to_version(version_string)
                    properties["version_string"] = version_string

                    # only add if version info has been extracted properly
                    try:
                        result[hoster].append(properties)
                    except KeyError:
                        result[hoster] = list()
                        result[hoster].append(properties)

                except AttributeError:
                    pass # version info could not be extracted


        downloads = Downloads()
        downloads.downloads_string = json.dumps(result)
        downloads.put()

        # Sort each downloads by version
        for hoster, download_links in result.iteritems():
            result[hoster] = tuple(sorted(download_links, key=lambda item: item["version"], reverse=True))

        return result
示例#2
0
    assemble_folder_path = os.path.join(assemble_folder, "diribeo")
    if os.path.isdir(assemble_folder_path):
        print "Deleting diribeo"
        shutil.rmtree(assemble_folder_path)

    print "Starting copy"
    shutil.copytree("../src", assemble_folder_path, ignore=ignore_dir)
    print "Finished copy action"

    makeArchive(dirEntries(assemble_folder, True), zip_name)
    print "Finished creating archieve"

    print "Uploading"
    abs_zip_path = os.path.abspath(zip_name)
    rsapi = RapidShareAPI(credentials)
    rs_fileid = rsapi.upload_file(abs_zip_path)

    hfapi = HotFileAPI(credentials)
    hf_fileid = hfapi.upload_file(abs_zip_path, folderid="1701142", hashid="2e37c99", path="diribeo")
    hfapi.set_direct_download(hf_fileid)
    print "Finished Uploading"

    print "Notify web server"
    query = urllib.urlencode({"username": username,
                              "password": password})
    base_url = ["http", "diribeo2010.appspot.com", "/tasks/updatedownloads_v1", "", query, ""]
    result = urllib2.urlopen(urlparse.urlunparse(base_url))
    for line in result:
        if "OK" in line:
            print "Notification was successful"