Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Commit

Permalink
final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-wasewicz committed Feb 24, 2016
1 parent aa6d2c8 commit 0b8b9bf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
4 changes: 2 additions & 2 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
p = Piazza()
p.user_login()

course = p.network(argv[1])
course = p.network(sys.argv[1])

mapSave = {}

Expand All @@ -16,5 +16,5 @@
print id
mapSave[id] = content

with open("posts.json","wb") as f:
with open("posts183.json","wb") as f:
f.write(json.dumps(mapSave))
65 changes: 65 additions & 0 deletions profile183.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import jsim
import logging
import os
import re
import sys

from potatobot import PotatoBot

JSIM_FILE = "posts183.json"
JSIM_THRESHOLD = .32
JSIM_LIMIT = 50

def die(message):
sys.stderr.write("{}\n".format(message))
sys.exit(1)


def get_bot():
config_sources = {
"email": "PBOT_EMAIL",
"password": "PBOT_PASSWORD",
"class_code": "PBOT_CLASS_CODE",
}

config = {}
for var, source in config_sources.items():
try:
config[var] = os.environ[source]
except KeyError:
die("`{}` must be set in the environment.".format(
source
))

return PotatoBot.create_bot(**config)




def main():
logging.basicConfig(level=logging.INFO)
bot = get_bot()

@bot.handle_post
def check_for_duplicate_posts(post_info):
if post_info.status != "private":

jsim.save(JSIM_FILE, post_info.id, post_info.text)

sim_list = jsim.getSimilarities(JSIM_FILE, post_info.id, post_info.text, JSIM_THRESHOLD)

sim_list = [i for i in sim_list if int(i[1]) < post_info.id]
answers = ", ".join("@" + x[1] for x in sim_list[:JSIM_LIMIT])
if sim_list:
return """
<p>Hi! It looks like this question has been asked before or there is a related post.
You may find these posts helpful: {}</p>
<p></p>
<p>If you found your answer in one of the above, please mark your question as a note
to resolve it / specify which one answered your question. </p>
""".format(answers)

bot.run_forever()

if __name__ == "__main__":
main()

0 comments on commit 0b8b9bf

Please sign in to comment.