Python Send to and figure out POST - python

Recently, I've been attempting to figure out how I can find out what an unlabeled POST is, and send to it using Python.
The issue of the matter is I'm attempting to make a chat bot entirely in Python in order to increase my knowledge of the language. For said bot, I'm attempting to use a chat-box that runs entirely on jQuery. The issue with this is it has no knowledgeable POST or GET statements associated with the chat-box submissions.
How can I figure out what the POST and GET statements being sent when a message is submitted, and somehow use that to my advantage to send custom POST or GET statements for a chat-bot?
Any help is appreciated, thanks.

You need a server in order to be able to receive any GET and POST requests, one of the easier ways to get that is to set up a Django project, ready in minutes and then add custom views to handle the request you want properly.

Related

Python is there a way to read custom headers and send a response back

Ok so I am new to python as a whole. That said I don't know what I'm really looking for to ask this question properly. I know this has to be possible though. I want to ask this before really digging in and finding out I did something wrong and have to do it all over.
All in all what I want to know is, from the front end of my stack I want to pass down custom HTTP headers (which I can do with my Ajax calls, currently). The question is how do I actually read said headers? Similarly how can I pass back up from the server custom headers via python.
You can access custom header in Django view:
request.META.get("Custom_Header")
For django:
How to add an HTTP header to all Django responses
You can definitely do it in the front end. You can do it with Javascript's native XMLHttpRequest, the newer fetch API, jQuery, or some other library (like axios).

How to handle multireddits with praw

does anybody have any experience with handling multireddits with PRAW?
I need to get a list of multi's for a logged in user (that should be http://www.reddit.com/dev/api/oauth#GET_api_multi_mine) and then get a list of subbreddits in each multi.
For the life of me, I can't figure out how to do this with PRAW.
Thanks!
It's not implemented (yet).
You can send the requests through get_content, which would allow you to take advantage of some of PRAW's features such as request throttling, caching and objects rather than json. It will still be some work.
I'll update this comment when multireddit functionality is implemented in PRAW.

How to implement a simple Google Checkout callback function with Django?

I have a simple 'Buy Now' Google Checkout button on my Django site (very simple; no basket or anything more fancy). What I want is for Google to send a notification to a URL on my server once a new order has been processed. The notification should tell me the customer's email address and name (preferably as simple POST params). Then I can take this info and set up a user account, send out a confirmation email, etc.
This sounds simple. However, all I can find by way of documentation on Google's site is a dense and impenetrable thicket of competing versions, protocols, and APIs with no clear tutorials or example code. It is a nightmare.
Furthermore, I can see no obvious way of testing out the functionality. I continually see references to a 'sandbox', but I can find no concrete information on what this is or how to set it up. The URL 'sandbox.google.com' returns a 503 error.
Can anybody give me a pointer?
Thanks in advance.
Tom
Take a look at how Satchmo handles notifications in: payment.modules.google

Distinguishing between GET and POST data in CherryPy?

I've been deciding between Python web frameworks for a project of mine and I've really liked how lightweight, flexible, and concise CherryPy is compared to others. The only problem I'm having is I can't find any documentation on how to distinguish between data sent via GET and via POST.
For example, I don't want users to be able to provide their login credentials through a GET request (http://example.com/login?username=user&password=pass) but, according to CherryPy's tutorial, all data is sent as method parameters, no matter what HTTP method they're sent as. Is there some way to say I only want the POST data or do I have to use MethodDispatcher?
Thanks!
See the docs.
A string containing the HTTP method, such as "GET" or "POST". Set
in the "run" phase.
looks like checking cherrypy.request.method is what you want to do.

Facebook Style Wall / Activity log - General design help

I'm building a face-book style activity stream/wall. Using python/app engine. I have build the activity classes based on the current activity standard being used by face-book, yahoo and the likes. i have a Chanel/api system built that will create the various object messages that live on the wall/activity stream.
Where i can use some help is with some design ideas on how the wall should work. as follows:
I am using a fan out system. When something happens i send a message - making one copy but relating it to all that have subscribed to the channel it is written on. This is all working fine.
My original idea was to then simple use a query to show a wall - a simple get all the messages for a given channel or user. Which is fine.
But now I'm wondering if that is the best way to do it. I'm wondering if as the wall is a historical log that really should show "what has happened recently say last 90 days at the most. And that i will use Ajax to fetch the new messages. Is it better to use the message api i have built to send messages and then use a simple model/class/ to store the messages that form the wall for each user. Almost storing the raw HTML for each post. If each post was stored with its post date, object ref (comment,photo,event) it would be very easy to update/insert new entries in the right places and remove older ones. It would also be easy ajax side to simply listen for a new message. Insert it and continue.
I know their have been a lot of posts re "the wall" & "activity" stream does anyone have any thoughts i if my ideas are correct or off track?
Thanks
This is pretty much exactly what Brett Slatkin was talking about in his 2009 I/O talk. I'd highly recommend watching it for inspiration, and to see how a member of the App Engine team solves this problem.
Also you can check Opensocial API for design and maybe http://github.com/sahid/gosnippets.

Categories