Advertisement
Guest User

fraudcatch.py

a guest
Nov 10th, 2020
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.29 KB | None | 0 0
  1. import json
  2. import requests
  3. import sys
  4.  
  5. def findfraud(STATE):
  6.     with open(STATE + '.json', encoding="utf8") as f:
  7.         x = json.load(f)
  8.     segments = x["data"]["races"][0]["timeseries"]
  9.     trumpDiff = 0
  10.     bidenDiff = 0
  11.     print("Checking " + str(len(segments)) + " time segments.")
  12.     for i in range(len(segments)):
  13.         # Skip first segment
  14.         if i != 0:
  15.  
  16.             votesCounted        = segments[i]["votes"]                      # Votes counted at this time segment
  17.             trumpShare          = segments[i]["vote_shares"]["trumpd"]      # Trumps share of the vote
  18.             bidenShare          = segments[i]["vote_shares"]["bidenj"]      # Bidens share of thevote
  19.             lastVotesCounted    = segments[i-1]["votes"]                    # Votes counted in previous time segment
  20.             lastTrumpShare      = segments[i-1]["vote_shares"]["trumpd"]    # Trumps share of vote in previous segment
  21.             lastBidenShare      = segments[i-1]["vote_shares"]["bidenj"]    # Bidens share of vote in previous segment
  22.             trumpCount          = votesCounted      * trumpShare            # Trumps current vote count
  23.             lastTrumpCount      = lastVotesCounted  * lastTrumpShare        # Trumps previous vote count
  24.             bidenCount          = votesCounted      * bidenShare            # Bidens current vote count
  25.             lastBidenCount      = lastVotesCounted  * lastBidenShare        # Bidens previous vote count
  26.  
  27.             # Check if Trump lost votes
  28.             if trumpCount < lastTrumpCount:
  29.                 # Check if Biden gained votes
  30.                 if bidenCount > lastBidenCount:
  31.                     trumpVoteDiff = trumpCount - lastTrumpCount
  32.                     bidenVoteDiff = bidenCount - lastBidenCount
  33.                     # Print segment info
  34.                     print ("WARNING: Anomalous voting data against Trump found. index[" + str(i-1) + "]->[" + str(i) +"]")
  35.                     # Print lost votes
  36.                     print ("       : Trump vote differential: " + str(trumpVoteDiff))
  37.                     print ("       : Biden vote differential: " + str(bidenVoteDiff))
  38.                     trumpDiff += trumpVoteDiff
  39.                     bidenDiff += bidenVoteDiff
  40.  
  41.             # For the sake of fairness, we should check if any of these errors are going the other way
  42.             if bidenCount < lastBidenCount:
  43.                 # Check if Biden gained votes
  44.                 if trumpCount > lastTrumpCount:
  45.                     trumpVoteDiff = trumpCount - lastTrumpCount
  46.                     bidenVoteDiff = bidenCount - lastBidenCount
  47.                     # Print segment info
  48.                     print ("WARNING: Anomalous voting data against Biden found. index[" + str(i-1) + "]->[" + str(i) +"]")
  49.                     # Print lost votes
  50.                     print ("       : Trump vote differential: " + str(trumpVoteDiff))
  51.                     print ("       : Biden vote differential: " + str(bidenVoteDiff))
  52.                     trumpDiff += trumpVoteDiff
  53.                     bidenDiff += bidenVoteDiff
  54.  
  55.     print("State: " + STATE)
  56.     print ("Total Trump Differential: " + str(trumpDiff) + " Flo")
  57.     print ("Total Biden Differential: " + str(bidenDiff) + " Flo")
  58.  
  59. def findfraud2(STATE):
  60.     with open(STATE + '.json', encoding="utf8") as f:
  61.         x = json.load(f)
  62.     segments = x["data"]["races"][0]["timeseries"]
  63.     TotalVotesLost = 0
  64.     for i in range(len(segments)):
  65.         if i != 0:
  66.  
  67.             votesCounted        = segments[i]["votes"]                      # Votes counted at this time segment
  68.             lastVotesCounted    = segments[i-1]["votes"]                    # Votes counted in previous time segment
  69.  
  70.             if votesCounted < lastVotesCounted:
  71.                 TotalVotesLost += votesCounted - lastVotesCounted
  72.     print (TotalVotesLost)
  73.  
  74. def main():
  75.     state = ""
  76.     if len(sys.argv) < 2:
  77.         state = input("Enter a state: ").lower()
  78.     else:
  79.         state = sys.argv[1].lower()
  80.     url = "https://static01.nyt.com/elections-assets/2020/data/api/2020-11-03/race-page/" + state + "/president.json"
  81.     data = requests.get(url, allow_redirects=False)
  82.     open(state + '.json', 'wb').write(data.content)
  83.     findfraud(state)
  84.     findfraud2(state)
  85.  
  86. if __name__ == "__main__":
  87.     main()
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement