Guest User

Modified Python Code for Pede's vote-loss analysis

a guest
Nov 11th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.40 KB | None | 0 0
  1. # Program to find any vote-switching due to problems in the vote counting machines
  2. # fraudcatchv2.py (modified from what Pede created)
  3.  
  4. import json
  5.  
  6.  
  7. def findfraudAgainstTrump(NAME):
  8.     """ Function to find vote-switching fraud against Trump in any particular US state 2020 election JSON file """
  9.     with open(NAME + '.json', encoding="utf8") as f:
  10.         x = json.load(f)
  11.     TotalVotesLost = 0
  12.  
  13.     # If the votes in a particular time-series entry for Trump are less than in the previous time-series entry, but those for Biden are more,
  14.     # calculate the number of votes switched in favor of Biden.
  15.     for i in range(len(x["data"]["races"][0]["timeseries"])):
  16.         if i != 0 and x["data"]["races"][0]["timeseries"][i]["votes"] * x["data"]["races"][0]["timeseries"][i]["vote_shares"]["trumpd"] < x["data"]["races"][0]["timeseries"][i-1]["votes"] * x["data"]["races"][0]["timeseries"][i-1]["vote_shares"]["trumpd"]:
  17.             if x["data"]["races"][0]["timeseries"][i]["votes"] * x["data"]["races"][0]["timeseries"][i]["vote_shares"]["bidenj"] > x["data"]["races"][0]["timeseries"][i-1]["votes"] * x["data"]["races"][0]["timeseries"][i-1]["vote_shares"]["bidenj"]:
  18.                 print ("Index : " + str(i) + " ~~~ " + \
  19.                             "EEVP_SOURCE: " + x["data"]["races"][0]["timeseries"][i]["eevp_source"] + " ~~~ " + \
  20.                             x["data"]["races"][0]["timeseries"][i]["timestamp"] + " ~~~ " + \
  21.                             " Past Index : " + str(i-1) + " ~~~ " + \
  22.                             "EEVP_SOURCE: " + x["data"]["races"][0]["timeseries"][i-1]["eevp_source"] + " ~~~ " + \
  23.                             x["data"]["races"][0]["timeseries"][i-1]["timestamp"] + " ~~~ ")
  24.                 print (x["data"]["races"][0]["timeseries"][i]["votes"] * x["data"]["races"][0]["timeseries"][i]["vote_shares"]["trumpd"] - x["data"]["races"][0]["timeseries"][i-1]["votes"] * x["data"]["races"][0]["timeseries"][i-1]["vote_shares"]["trumpd"])
  25.                 TotalVotesLost += x["data"]["races"][0]["timeseries"][i]["votes"] * x["data"]["races"][0]["timeseries"][i]["vote_shares"]["trumpd"] - x["data"]["races"][0]["timeseries"][i-1]["votes"] * x["data"]["races"][0]["timeseries"][i-1]["vote_shares"]["trumpd"]
  26.     print ("Votes reduced for Trump: ", str(str(TotalVotesLost)  + " Flo" + "\n"))
  27.  
  28. def findfraudAgainstBiden(NAME):
  29.     """ Function to find vote-switching fraud against Biden in any particular US state 2020 election JSON file """
  30.     with open(NAME + '.json', encoding="utf8") as f:
  31.         x = json.load(f)
  32.     TotalVotesLost = 0
  33.  
  34.     # If the votes in a particular time-series entry for Biden are less than in the previous time-series entry, but those for Trump are more,
  35.     # calculate the number of votes switched in favor of Trump.
  36.     for i in range(len(x["data"]["races"][0]["timeseries"])):
  37.         if i != 0 and x["data"]["races"][0]["timeseries"][i]["votes"] * x["data"]["races"][0]["timeseries"][i]["vote_shares"]["bidenj"] < x["data"]["races"][0]["timeseries"][i-1]["votes"] * x["data"]["races"][0]["timeseries"][i-1]["vote_shares"]["bidenj"]:
  38.             if x["data"]["races"][0]["timeseries"][i]["votes"] * x["data"]["races"][0]["timeseries"][i]["vote_shares"]["trumpd"] > x["data"]["races"][0]["timeseries"][i-1]["votes"] * x["data"]["races"][0]["timeseries"][i-1]["vote_shares"]["trumpd"]:
  39.                 print ("Index : " + str(i) + " ~~~ " + \
  40.                             "EEVP_SOURCE: " + x["data"]["races"][0]["timeseries"][i]["eevp_source"] + " ~~~ " + \
  41.                             x["data"]["races"][0]["timeseries"][i]["timestamp"] + " ~~~ " + \
  42.                             " Past Index : " + str(i-1) + " ~~~ " + \
  43.                             "EEVP_SOURCE: " + x["data"]["races"][0]["timeseries"][i-1]["eevp_source"] + " ~~~ " + \
  44.                             x["data"]["races"][0]["timeseries"][i-1]["timestamp"] + " ~~~ ")
  45.                 print (x["data"]["races"][0]["timeseries"][i]["votes"] * x["data"]["races"][0]["timeseries"][i]["vote_shares"]["bidenj"] - x["data"]["races"][0]["timeseries"][i-1]["votes"] * x["data"]["races"][0]["timeseries"][i-1]["vote_shares"]["bidenj"])
  46.                 TotalVotesLost += x["data"]["races"][0]["timeseries"][i]["votes"] * x["data"]["races"][0]["timeseries"][i]["vote_shares"]["bidenj"] - x["data"]["races"][0]["timeseries"][i-1]["votes"] * x["data"]["races"][0]["timeseries"][i-1]["vote_shares"]["bidenj"]
  47.     print ("Votes reduced for Biden: ", str(str(TotalVotesLost)  + " Flo" + "\n"))
  48.  
  49. def findfraud2(NAME):
  50.     """ Function to find total votes lost (for both candidates together) in any particular US state 2020 election JSON file """
  51.     with open(NAME + '.json', encoding="utf8") as f:
  52.         x = json.load(f)
  53.     TotalVotesLost = 0
  54.     for i in range(len(x["data"]["races"][0]["timeseries"])):
  55.         if i != 0 and x["data"]["races"][0]["timeseries"][i]["votes"] < x["data"]["races"][0]["timeseries"][i-1]["votes"]:
  56.             TotalVotesLost += x["data"]["races"][0]["timeseries"][i]["votes"] - x["data"]["races"][0]["timeseries"][i-1]["votes"]
  57.     print (TotalVotesLost)
  58.  
  59. def main():
  60.     """ The main part of the program, where execution starts """
  61.  
  62.     list_of_state_files_without_json_extension = ["alabama", "alaska", "arizona",
  63.         "arkansas", "california", "colorado", "connecticut", "delaware",
  64.         "districtofcolumbia", "florida", "georgia", "idaho", "illinois", "indiana",
  65.         "iowa", "jersey", "kansas", "kentucky", "louisiana", "maine", "maryland",
  66.         "massachusetts", "mexico", "michigan", "minnesota", "mississippi", "missouri",
  67.         "montana", "nebraska", "nevada", "newhamp", "newyork", "northcarolina",
  68.         "northdakota", "ohio", "oklahoma", "oregon", "pennsylvania", "rhode",
  69.         "southcarolina", "southdakota", "tenn", "texas", "utah", "vermont", "virginia",
  70.         "washington", "westvirginia", "wisconsin", "wyoming"]
  71.  
  72.     for state in list_of_state_files_without_json_extension:
  73.         print(state.upper(), " VOTES REDUCED FOR TRUMP - ANALYSIS")
  74.         print("------------------------------")
  75.         findfraudAgainstTrump(state)
  76.         print(state.upper(), " VOTES REDUCED FOR BIDEN - ANALYSIS")
  77.         print("------------------------------")
  78.         findfraudAgainstBiden(state)
  79.         print(state.upper(), " VOTES LOST (FOR BOTH CANDIDATES TOGETHER) - ANALYSIS")
  80.         print("------------------------------")
  81.         findfraud2(state)
  82.         print()
  83.         print()
  84.  
  85. if __name__ == '__main__':
  86.     main()
  87.  
Advertisement
Add Comment
Please, Sign In to add comment