i need to write code that will read messages from user and reply but i’ve got to use exactly this function: GetDialogs Request, not event method. please help, can't find any information about it
The request you mention, GetDialogsRequest, is part of what's known as "raw API". Both pages of the documentation contain examples. However, as noted in the first link, you probably want to use client.iter_dialogs (the link again contains an example):
# Print all dialog IDs and the title, nicely formatted
async for dialog in client.iter_dialogs():
print('{:>14}: {}'.format(dialog.id, dialog.title))
This may not be the request you're looking for though, as this returns a list of open conversations. Following the documentation would be a good way to understand what's happening and what you should use.
Related
I'm using praw to write a bot for reddit. I already know how to use the get_comments() function to get all the comments in a subreddit. However, I would like to get the titles of all the posts in a subreddit, however, after going through the docs for praw, I could not find a function which does so.
I just want to go into a subreddit, and fetch all the titles of the posts, and then store them in an object.
Could someone tell me how I go around achieving this?
import praw
r=praw.Reddit('demo')
subreddit=r.get_subreddit('stackoverflow')
for submission in subreddit.get_hot(limit=10):
print submission.title
This information is available in the PRAW documentation.
Seems pretty late but anyways you can go through the official reddit api JSON responses format. From there you can see all the attributes that are available to you for a particular object.
Here's the github link for the reddit API
Edit: You can also use pprint(vars(object_name))
As the title says, I'm unable to find the function in PRAW to reply to a post on Reddit.
I've written a rather simple bot so far, which looks for new posts on a certain subreddit. My problem is that once finding the submission, I can't find how to post a reply to it.
It's unclear if by "submission" you mean a submission to reddit or if you're referencing a comment on a submission to reddit. If it's the former, you're looking for the Submission#add_comment method. If you have the submission bound to variable name s, then you can do the following:
s.add_comment('This is my comment. There are many like it, but this one is mine.')
If you're looking for how to reply to a comment, you want to use the Comment#reply method. If you have the comment bound to variable name c, then you can do the following:
c.reply("Here is a reply to your comment.")
As of October 2018, submission.add_comment() is no longer possible in PRAW.
The new call is submission.reply()
According to their documentation:
This should be enough to get the hottest new reddit submissions:
r = client.get(r'http://www.reddit.com/api/hot/', data=user_pass_dict)
But it doesn't and I get a 404 error. Am I getting the url for data request wrong?
http://www.reddit.com/api/login works though.
Your question specifically asks what you need to do to get the "hottest new" submissions. "Hottest new" doesn't really make sense as there is the "hot" view and a "new" view. The URLs for those two views are http://www.reddit.com/hot and http://www.reddit.com/new respectively.
To make those URLs more code-friendly, you can append .json to the end of the URL (any reddit URL for that matter) to get a json-representation of the data. For instance, to get the list of "hot" submissions make a GET request to http://www.reddit.com/hot.json.
For completeness, in your example, you attempt to pass in data=user_pass_dict. That's definitely not going to work the way you expect it to. While logging in is not necessary for what you want to do, if you happen to have need for more complicated use of reddit's API using python, I strongly suggest using PRAW. With PRAW you can iterate over the "hot" submissions via:
import praw
r = praw.Reddit('<REPLACE WITH A UNIQUE USER AGENT>')
for submission in r.get_frontpage():
# do something with the submission
print(vars(submission))
According to the docs, use /hot rather than /api/hot:
r = client.get(r'http://www.reddit.com/hot/', data=user_pass_dict)
I have built a app that handles incoming sms for a short number. We might have several campaigns running at the same time, each with different mechanics and keywords etc.
At the moment I am using Django to handle this.
My biggest concern atm is that the consumer who is using out service is a very low LSM market in South Africa. The sms's come ins weird ways and I get allot of wrong entries.
Im trying to rethink the way to interpret the sms and would like some ideas.
At the moment it basically works like this:
Get the SMS, I split it by a ' or * THEN look first for the KEYWORD. All campaigns have Keywords and I run through a list of live campaign keywords to see if there is a match in the message. Then I go on in the split message and compare or find more words if needed. I need to reply based on the message, like the KEYWORD is there, but not the 2nd or 3rd or what ever parameter.
Megan from Twilio here.
You may or may not be using a Twilio shortcode. But I think your question relates to a little guide we have on How to Build a SMS Keyword Response Application.
The example there is in PHP but you can get started in Python here and your code might look like:
def sms():
r = twiml.Response()
body = request.form['Body']
if KEYWORD in body:
//do some action
I Have an IRC bot I'm working on, and one of the features I would like it to have is to take any link a person posts and use BeautifulSoup to parse that page. Now, I have the bot working, getting the messages people post, etc. But, how would I pull a link from the IRC message? Say someone says this:
Person: Check out http://www.site.com, it's cool!
How would I take the link out and assign it to a variable for later use, without pulling the other parts of the message?
I think it's something to do with regexs, but I'm not sure.
You will indeed need to use regular expressions.
There's a decent article with a regular expression for matching URLs and somewhat of a description of what it's doing at daring fireball.
You can look at how Django does it here.
Finally, Python's regular expression documentation may also be useful.
You are on the exact track to finish this. You gave yourself the answer with the last sentence of your question. You will use a regular expression with a capture group to get the url and from there you can parse/grab the page that the user has said in the irc.
This site may be of some use for you: http://www.regular-expressions.info/