# run within ipython (started using "python manage.py shell") using "%run testing.py" # imports import datetime import sys # import the RedditCollector class from reddit_collect.redditCollector import RedditCollector # import reddit_collect models. import reddit_collect.models # make an instance reddit_collector = RedditCollector() # initialize bare minimum connection parameters. reddit_collector.user_agent = "reddit comment collector v0.1" # set to escape 4-byte Unicode characters (cursed mysql). reddit_collector.convert_4_byte_unicode_to_entity = True # get reddiwrap instance reddiwrap = reddit_collector.create_reddiwrap_instance()
# python imports import datetime # import the RedditCollector class from reddit_collect.redditCollector import RedditCollector # make an instance reddit_collector = RedditCollector() # initialize bare minimum connection parameters. reddit_collector.user_agent = "reddit post collector v0.1 by /u/jonathan_morgan" # OR reddit_collector.user_agent = "reddit comment collector v0.1 by /u/jonathan_morgan" # optional, if you need to log in: #reddit_collector.username = "******" #reddit_collector.password = "******" # optional - also can set path to store cookies, if you want to persist them. reddit_collector.cookie_file_path = "cookies.txt" # optional - if your version of mysql doesn't support utf8mb4 (unicode # characters greater than 3-bytes), set this to true and it will keep all # unicode characters 3 bytes and less, turn those that are 4 bytes long # into XML entities, so they are preserved, but don't break database. # set to escape 4-byte Unicode characters (cursed mysql). reddit_collector.convert_4_byte_unicode_to_entity = True #============================================================================ # ==> Collect Posts #============================================================================
# init connection information # BEFORE RUNNING, SET reddit_post_id #reddit_post_id = '1cp0i3' # 113 reddit_post_id = '1d67nv' # 569 print( "testing post " + reddit_post_id ) #================================================================================ # collect comments using RedditCollector #================================================================================ # make an instance reddit_collector = RedditCollector() # initialize connection parameters. reddit_collector.user_agent = my_user_agent reddit_collector.username = my_username reddit_collector.password = my_password # set collector to output details reddit_collector.do_output_details = False # set bulk collection flag (defaults to True) #reddit_collector.do_bulk_create = False # initialize summary helper my_summary_helper = SummaryHelper() # get post QuerySet #post_qs = reddit_collect.models.Post.objects.filter( reddit_id = reddit_post_id ) post_qs = reddit_collect.models.Post.objects.filter( reddit_id__in = [ '1cp0i3', '1d67nv' ] )
# run within ipython (started using "python manage.py shell") using "%run testing.py" # import the RedditCollector class from reddit_collect.redditCollector import RedditCollector # make an instance reddit_collector = RedditCollector() # initialize bare minimum connection parameters. reddit_collector.user_agent = "reddit comment collector v0.1 by /u/jonathan_morgan" import reddit_collect.models post_qs = reddit_collect.models.Post.objects.filter( reddit_id = '1cp0i3' ) # num_comments? django_post = post_qs[ 0 ] print( django_post.num_comments ) # 115, at time of collection # pass the QuerySet to the collect_comments() method. reddit_collector.collect_comments( post_qs ) # refresh post. django_post = reddit_collect.models.Post.objects.get( reddit_id = '1cp0i3' ) # get reddiwrap post, so we can pull comments from reddit. comment_rw_post = django_post.create_reddiwrap_post() # get reddiwrap instance reddiwrap = reddit_collector.create_reddiwrap_instance() # fetch comments