<commit_before>#!/usr/bin/env python3

import time

import praw
import requests

# Import username and password
from config import *

HN_LIMIT = 50
REDDIT_LIMIT = 25

HN_TOP_URL = 'https://hacker-news.firebaseio.com/v0/topstories.json'
HN_ITEM = 'https://hacker-news.firebaseio.com/v0/item/{}.json'
HN_STORY = 'https://news.ycombinator.com/item?id={}'

def get_reddit_submissions():
    r = praw.Reddit(user_agent='crosslink_hackernews')
    r.login(REDDIT_USERNAME, REDDIT_PASS, disable_warning=True)
    submissions = r.get_subreddit('machinelearning').get_hot(limit=REDDIT_LIMIT)

    return [sub for sub in submissions
	if 'reddit.com' not in sub.url]

def get_hn_submissions():
    # Makes a request for each story, but couldn't find
    # a better way through their API
    hn_items = [requests.get(HN_ITEM.format(id)).json()
                for id in requests.get(HN_TOP_URL).json()[:HN_LIMIT]]

    return [(hn_story.get('url'), hn_story['id']) for hn_story in hn_items]

# Couldn't find a satisfying way to normalize urls,
def get_common_submissions(reddit_subs, hn_subs):
    return [
        (reddit_sub, hn_sub[1])
        for reddit_sub in reddit_subs for hn_sub in hn_subs
        if hn_sub[0] == reddit_sub.url
    ]

def post_comment(common_subs):
    for common_sub in common_subs:
        if not any(comm for comm in common_sub.comments if REDDIT_USERNAME in str(comm.author)):
            common_sub[0].add_comment('HN discussion: {}'.format(HN_STORY.format(common_sub[1])))
            time.sleep(1)

def main():
    reddit_subs = get_reddit_submissions()
    hn_subs = get_hn_submissions()
    common_subs = get_common_submissions(reddit_subs, hn_subs)
    post_comment(common_subs)

if __name__ == '__main__':<commit_msg>Fix indexing bug<commit_after>#!/usr/bin/env python3

import time

import praw
import requests

# Import username and password
from config import *

HN_LIMIT = 50
REDDIT_LIMIT = 25

HN_TOP_URL = 'https://hacker-news.firebaseio.com/v0/topstories.json'
HN_ITEM = 'https://hacker-news.firebaseio.com/v0/item/{}.json'
HN_STORY = 'https://news.ycombinator.com/item?id={}'

def get_reddit_submissions():
    r = praw.Reddit(user_agent='crosslink_hackernews')
    r.login(REDDIT_USERNAME, REDDIT_PASS, disable_warning=True)
    submissions = r.get_subreddit('machinelearning').get_hot(limit=REDDIT_LIMIT)

    return [sub for sub in submissions
	if 'reddit.com' not in sub.url]

def get_hn_submissions():
    # Makes a request for each story, but couldn't find
    # a better way through their API
    hn_items = [requests.get(HN_ITEM.format(id)).json()
                for id in requests.get(HN_TOP_URL).json()[:HN_LIMIT]]

    return [(hn_story.get('url'), hn_story['id']) for hn_story in hn_items]

# Couldn't find a satisfying way to normalize urls,
def get_common_submissions(reddit_subs, hn_subs):
    return [
        (reddit_sub, hn_sub[1])
        for reddit_sub in reddit_subs for hn_sub in hn_subs
        if hn_sub[0] == reddit_sub.url
    ]

def post_comment(common_subs):
    for common_sub in common_subs:
        if not any(comm for comm in common_sub[0].comments if REDDIT_USERNAME in str(comm.author)):
            common_sub[0].add_comment('HN discussion: {}'.format(HN_STORY.format(common_sub[1])))
            time.sleep(1)

def main():
    reddit_subs = get_reddit_submissions()
    hn_subs = get_hn_submissions()
    common_subs = get_common_submissions(reddit_subs, hn_subs)
    post_comment(common_subs)

if __name__ == '__main__':
{'fraction_non_alphanumeric': 0.1134020618556701, 'fraction_numerical': 0.00715922107674685, 'mean_word_length': 4.06966618287373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '267411', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1268, 'n_words': 269}