-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtpCitation.py
More file actions
54 lines (34 loc) · 1.27 KB
/
tpCitation.py
File metadata and controls
54 lines (34 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf8 -*-
import random
import json
'''Lancer les scrapper characters et quote avant de lancer ce programme.
utiliser la commande : scrapy runspider charactersScraper.py -o characters.json
Attention, fileQuotes et fileCharacters doivent correspondre au nom du fichier
creer avec cette commande'''
#Mettre les bons noms de clef et de fichier ci dessous
keyQuotes = "quote"
fileQuotes = "quotes.json"
keyCharacters = "character"
fileCharacters = "characters.json"
#initialisation de la valeur d'entrée utilisateur
userAnswer = " "
#Lecture fichier JSON
def readJson(file, key):
list=[]
with open(file) as f:
readData = json.load(f)
for item in readData:
list.append(item[key])
return list
#Choix d'un indice de liste au hasard
def randomQuotes (listX):
quoteToPrint = random.randint(0, len(listX)-1)
return quoteToPrint
#Creation des listes
listQuotes = readJson (fileQuotes, keyQuotes)
listCharacters = readJson (fileCharacters, keyCharacters)
#Main
while userAnswer != "B":
print ("\n" ,"{} vous dit : {}".format(listCharacters[ randomQuotes(listCharacters)], listQuotes[ randomQuotes(listQuotes)]))
userAnswer = input ("\nVeiller entrer une lettre. Preser \"B\" pour exit: ")
print ("\nMerci au revoir")