Ejemplo n.º 1
0
def post(arg):
    """defines post command"""

    postTypes = ["text", "photo", "quote", "link", "chat", "audio", "video"]
    postStates = ["published", "draft", "queue", "private"]

    args = arg.split(" ")

    if args[0] in postTypes:
        if args[0] == "text":
            if '"' in args[1]:
                quote_text = re.findall('"([^"]*)"', arg)
                text = ""

                if len(quote_text) > 1:
                    text = quote_text[0]

                text_post = {"title": "", "state": "", "blog": "", "tags": []}

                if "--title" in args:
                    if len(quote_text) == 1:
                        text_post['title'] = quote_text[0]
                    else:
                        text_post['title'] = quote_text[1]

                if "-s" in args:
                    state = args[args.index('-s') + 1]
                    if state in postStates:
                        text_post['state'] = state
                    else:
                        print "Invalid state value found: " + state
                        print "Posting now"

                if "-b" in args:
                    text_post['blog'] = args[args.index('-b') + 1]
                else:
                    text_post['blog'] = USERNAME

                if "-t" in args:
                    for s in args[args.index("-t") + 1:]:
                        if s not in ["--title", "-b", "-s"]:
                            text_post['tags'].append(s)
                        else:
                            break

                print text_post
                newPost = Post(client, text_post['blog'], "text", text_post['tags'])
                newPost.publish(text_post['state'], title=text_post['title'], body=text)

            else:
                print "No text content found! Text must be in quotes."
    else:
        print "Invalid post type: " + args[0]