Skip to content

Instantly share code, notes, and snippets.

@evan4498
Last active December 18, 2015 10:18
Show Gist options
  • Save evan4498/5767051 to your computer and use it in GitHub Desktop.
Save evan4498/5767051 to your computer and use it in GitHub Desktop.
packages.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2013 Rackspace
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import sys
import pyrax
import json
cls = pyrax.utils.import_class('pyrax.identity.rax_identity.RaxIdentity')
pyrax.identity = cls()
pyrax.set_credentials("USERNAME", "API_KEY")
cf = pyrax.cloudfiles
def main():
get_package()
def get_package():
package_file = open('packages.json').read()
package_json = json.loads(package_file)
for pos, i in enumerate(package_json):
print str(pos) + ":", i["name"]
for k in i["files"]:
print " ", k
option_choice = int(raw_input("Select the purchased package: "))
package_name = package_json[option_choice]["name"]
print ""
print "You have chosen to create temp urls for \"" + package_name +"\""
time = int(raw_input("How many minutes should this file be served for? "))
secs = time * 60
print ""
print "The customer will get the following files:"
for filename in package_json[option_choice]["files"]:
print filename + ":"
create_url(filename, secs)
def create_url(filename, secs):
my_key = "MAKE_UP_A_KEY"
cf.set_temp_url_key(my_key)
cont = cf.get_container("iso")
tempurl = cf.get_temp_url(cont.name, filename , seconds=secs, method="GET")
print tempurl
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment