PapyrusThePlant / strawpoll.py

A python wrapper for the Strawpoll API.
MIT License
7 stars 1 forks source link

submit_poll does not work #1

Closed doron-goldstein closed 7 years ago

doron-goldstein commented 7 years ago

even running your example, poll.url returns a blank string.

PapyrusThePlant commented 7 years ago

This needs more info as things are fine on my end.

PapyrusThePlant commented 7 years ago

No follow up, considering this solved.

jwshields commented 7 years ago

I think I am able to repro this. Running Python 3.6.2 on Windows

The code I'm using, more or less identical to the example listed in the docs.

    @commands.command(aliases=['poll'], hidden=True)
    async def straw(self, ctx, *args):
        poller = strawpoll
        title = args[0]
        arglist = list(args)
        arglist.pop(0)
        topoll = poller.Poll(title=str(title), options=arglist)
        await poller.API.submit_poll(poll=topoll)
        print("submitted poll")
        print(topoll.url)

Error comes from the submit_poll line. 2017-10-12 09:16:53.871996: Command raised an exception: TypeError: submit_poll() missing 1 required positional argument: 'self'

jwshields commented 7 years ago

Okay, reworked the code a bit and got it working. But submit_poll isn't returning a URL for me.

    @commands.command(aliases=['poll'], hidden=True)
    async def straw(self, ctx, *args):
        spollapi = strawpoll.API()
        title = args[0]
        arglist = list(args)
        arglist.pop(0)
        topoll = strawpoll.Poll(title, arglist, multi=False)
        print("before poll submit")
        print(str("title = ") + topoll.title)
        print(str("options = "))
        print(topoll.options)
        await spollapi.submit_poll(poll=topoll, request_policy=0)
        print("after poll submit")
        print("before poll url")
        print(str(topoll.url))
        print("after poll url")

Output:

2017-10-12 16:36:45: Addon "MiscThings" loaded
before poll submit
title = awooooo
options = 
['option 1', 'option 2', 'option 3']
after poll submit
before poll url

after poll url
PapyrusThePlant commented 7 years ago

Quoting the example :

     # Creating a new poll
    p2 = strawpoll.Poll('lol?', ['ha', 'haha', 'hahaha', 'hahahaha', 'hahahahaha'])
    print(p2.id)                # None
    print(p2.url)               #

    # Submitting it on strawpoll
    p2 = await api.submit_poll(p2)
    print(p2.id)                # 10921552
    print(p2.url)               # http://www.strawpoll.me/10921552

Note that submit_poll returns a new Poll object. I should maybe make it clearer by using a different name for the variable.

doron-goldstein commented 7 years ago

Man, I forgot I even made this issue, sorry for the lacking info.

Anyway, pretty sure that's exactly what I did, it was a bit unclear when you pass a poll and receive a new one. Might be a welcome change to edit the passed Poll with the new id and url.

jwshields commented 7 years ago

Awesome. I didn't realize it returned a new object like that. That works. Thanks @PapyrusThePlant