praw

How to take different input types and do something different with each? Python 3.5

允我心安 提交于 2020-01-06 22:04:13
问题 So I am trying to make a Reddit bot for personal use, as a learning project, and I am having trouble adding error exceptions for inputs. Here is the entire source code: http://pastebin.com/DYiun1ux The parts that are solely in question here are while True: if type(thing_limit) == int: print("That is a number, thanks.") break elif type(thing_limit) == float: print("You need a whole number.") sys.exit() elif type(thing_limit) == str: print("You need a whole number.") sys.exit() else: print(

How to take different input types and do something different with each? Python 3.5

一笑奈何 提交于 2020-01-06 22:03:08
问题 So I am trying to make a Reddit bot for personal use, as a learning project, and I am having trouble adding error exceptions for inputs. Here is the entire source code: http://pastebin.com/DYiun1ux The parts that are solely in question here are while True: if type(thing_limit) == int: print("That is a number, thanks.") break elif type(thing_limit) == float: print("You need a whole number.") sys.exit() elif type(thing_limit) == str: print("You need a whole number.") sys.exit() else: print(

Python script receiving a UnicodeEncodeError: 'ascii' codec can't encode character

北慕城南 提交于 2019-12-31 05:12:37
问题 I have a simple Python script that pulls posts from reddit and posts them on Twitter. Unfortunately, tonight it began having issues that I'm assuming are because of someone's title on reddit having a formatting issue. The error that I'm reciving is: File "redditbot.py", line 82, in <module> main() File "redditbot.py", line 64, in main tweeter(post_dict, post_ids) File "redditbot.py", line 74, in tweeter print post+" "+post_dict[post]+" #python" UnicodeEncodeError: 'ascii' codec can't encode

Filter strings in a for loop by list of words for reddit bot

删除回忆录丶 提交于 2019-12-25 08:49:38
问题 So I'm trying to write a reddit bot to find articles with certain words in the title. Here's what I have so far: top_posts = page.hot(limit=20) for post in top_posts: title = post.title if title.lower() in ['word1', 'word2', 'word3']: print(title) If I replace the last 2 lines with... if 'word1' in title.lower(): print(title) then it'll print the titles that have word1 in them but when I put it into a list it won't. I want to use a list to match different spellings of the same word. What am I

Get string that was matched by regex?

随声附和 提交于 2019-12-24 02:44:53
问题 I got this code for a reddit bot: match = re.findall(r"(?i)\bword1\b|\bword2\b|\bword3\b", comment.body) which matches several words. How can I print which word was matched? 回答1: Look at this example. This may helps you import re f=open('sample.txt',"w") f.write("<p class = m>babygameover</p>") f.close() f=open('sample.txt','r') string = "<p class = m>(.+?)</p>" pattern = re.compile(string) text = f.read() search = re.findall(pattern,text) print search 来源: https://stackoverflow.com/questions

recursion max error when when using futures.ProcessPoolExecutor but not futures.ThreadPoolExecutor with PRAW wrapper

微笑、不失礼 提交于 2019-12-22 09:17:14
问题 I am using this code to scrape an API: submissions = get_submissions(1) with futures.ProcessPoolExecutor(max_workers=4) as executor: #or using this: with futures.ThreadPoolExecutor(max_workers=4) as executor: for s in executor.map(map_func, submissions): collection_front.update({"time_recorded":time_recorded}, {'$push':{"thread_list":s}}, upsert=True) It works great/fast with threads but when I try to use processes I get a full queue and this error: File "/usr/local/lib/python3.4/dist

Getting & instead of & in title return using PRAW

时光总嘲笑我的痴心妄想 提交于 2019-12-13 17:10:02
问题 I'm trying to get the top 25 of all time of a given subreddit using PRAW: import praw subreddit = 'gamedeals' r = praw.Reddit(user_agent='getting top 25 of all time by /u/sqrg') submissions = r.get_subreddit(subreddit).get_top_from_all(limit=25) titlesFile = open("text.txt", 'w') for s in submissions: titlesFile.write(s.title.encode('utf-8', 'replace') + '\n') titlesFile.close() I get the following error: UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 63: ordinal

Cannot find PRAW config file when wrapping application with py2app

帅比萌擦擦* 提交于 2019-12-13 04:43:05
问题 I'm trying to wrap my Python script into an application using py2app, but when I try to run the app I'm getting this PRAW related error: Exception: Could not find config file in any of: ['/Users/username/CS/Applicationame/dist/applicationname.app/Contents/Resources/lib/python2.7/site-packages.zip/praw/praw.ini', '/Users/username/.config/praw.ini', 'praw.ini'] The strange thing is I navigated to the first path, unzipped site-packages.zip and found praw.ini inside /praw, so I'm not really sure

“AttributeError: '_NotSet' object has no attribute 'lower'” when a PRAW python file is converted to an exe using Pyinstaller

扶醉桌前 提交于 2019-12-13 03:56:01
问题 As the title says. When I execute the converted python file (the .exe) I get the following output: Traceback (most recent call last): File "background.py", line 10, in <module> File "site-packages\praw\reddit.py", line 129, in __init__ File "site-packages\praw\config.py", line 72, in __init__ File "site-packages\praw\config.py", line 98, in _initialize_attributes File "site-packages\praw\config.py", line 31, in _config_boolean AttributeError: '_NotSet' object has no attribute 'lower' [1692]

Python Praw skipping sticky in subreddits

冷暖自知 提交于 2019-12-11 05:57:38
问题 I am trying to loop through subreddits, but want to ignore the sticky posts at the top. I am able to print the first 5 posts, unfortunately including the stickies. Various pythonic methods of trying to skip these have failed. Two different examples of my code below. subreddit = reddit.subreddit(sub) for submission in subreddit.hot(limit=5): # If we haven't replied to this post before if submission.id not in posts_replied_to: ##FOOD if subreddit == 'food': if 'pLEASE SEE' in submission.title: