| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #!/usr/bin/python3
- import json
- import sys
- from datetime import datetime
- def import_array(filename):
- # Load the JSON file
- with open(filename, 'r') as f:
- data = json.load(f)
- # Access the "messages" array
- array = data['messages']
- return array
- def check_challenge_win(message):
- # Check that the message has text and that the text is "1337"
- if "text" in message and message["text"] == "1337":
- # Check if the message was edited, return false
- if "edited" in message:
- return False
- else:
- # get the hour and minutes from the date
- dt = datetime.fromtimestamp(int(message["date_unixtime"]))
-
- #finally, check if the hour is 13 and minute is 37
- if dt.hour == 13 and dt.minute == 37 :
- return True
- else:
- return False
- def main():
- # Get the file name from the first command line argument
- filename = sys.argv[1]
- # Import the array from the JSON file
- messages = import_array(filename)
-
- # create a dict containing the number of wins for each sender
- wins = {}
- # check the messages
- for message in messages:
- if(check_challenge_win(message)):
- #print("Message gagnant de " + message["from"] + " le " + message["date"])
- #If it's the first win, add the key with value 1
- if message["from"] not in wins:
- wins[message["from"]] = 1
- # Else, add 1 to the number of wins
- else:
- wins[message["from"]] += 1
-
- # print the resulting wins dict
- print(wins)
- if __name__ == '__main__':
- main()
|