Advertisement
Guest User

Untitled

a guest
Jan 29th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. __author__ = 'agentnola'
  2. import praw
  3. import json
  4. import gspread
  5. from oauth2client.client import SignedJwtAssertionCredentials
  6.  
  7. json_key = json.load(open('VoteCounter2-af942bc69325.json'))
  8. scope = ['https://spreadsheets.google.com/feeds']
  9.  
  10. credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'].encode(), scope)
  11. r = praw.Reddit("Vote Counting Bot")
  12. gc = gspread.authorize(credentials)
  13. sh = gc.open('MHoL Master Sheet')
  14. wks = sh.worksheet("VII - Amendment Votes")
  15.  
  16. #print("Input thread id")
  17. #thread = raw_input()
  18.  
  19. #print("Input bill number")
  20. #billnum = raw_input()
  21.  
  22. user = str(input("Reddit Username:"))
  23.  
  24.  
  25. print("Reddit Password:")
  26. password = str(input())
  27. r.login(user,password)
  28.  
  29. print("Post Voting Thread Link")
  30. tread = str(input())
  31. print("Post billnumber(without the B infront of it)")
  32. bill = 'B'+input()
  33.  
  34.  
  35.  
  36. def VoteCount(thread,billnum):
  37. column = int(wks.find(billnum).col)
  38.  
  39. already_done = []
  40. submission = r.get_submission(thread)
  41. comments = praw.helpers.flatten_tree(submission.comments)
  42.  
  43. for comment in comments:
  44. if comment.id not in already_done:
  45. print(comment.body)
  46. print(comment.author)
  47. try:
  48. already_done.append(comment.id)
  49. if "Not" not in str(comment.body).lower():
  50. already_done.append(comment.id)
  51. row = int(wks.find(str(comment.author).lower()).row)
  52.  
  53. val = wks.cell(row,column)
  54. if "N/A" not in val.value:
  55. wks.update_cell(row,column,"Con")
  56.  
  57. if "Not Content" in str(comment.body).lower():
  58. already_done.append(comment.id)
  59. row = wks.find(str(comment.author).lower()).row
  60. val = wks.cell(row,column).value
  61. if "N/A" not in val:
  62. wks.update_cell(row,column,"Not")
  63. except gspread.exceptions.CellNotFound:
  64. print("Automod Comment")
  65.  
  66.  
  67.  
  68. def deformat():
  69. cell_list = wks.range("C3:C141")
  70. for cell in cell_list:
  71. value = str(cell.value).lower()
  72.  
  73.  
  74.  
  75. wks.update_cell(cell.row,cell.col,value)
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. ##deformat()
  84. VoteCount(tread,bill)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement