Python Forum
Trying to sort a MYSQL Database
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to sort a MYSQL Database
#9
Ok thank you for your help, i've with this working program:

 db=MySQLdb.connect(host='localhost',user='root',passwd='eisti0001',db='Citela')
cur=db.cursor()
QUERY="""SELECT details from Tri"""
cur.execute(QUERY)
#result est une liste contenant les détails
result_details=cur.fetchall()
QUERY="""SELECT id from Tri"""
cur.execute(QUERY)
#result est une liste contenant les id
result_id=cur.fetchall()
QUERY="""SELECT nom from Tri"""
cur.execute(QUERY)
#result est une liste contenant les titre
result_nom=cur.fetchall()
#On teste les mots clés un par un
MC = ['route','autoroute','éclairage','public','parking','couvert','stationnement','rue','habitat',
          'logement','transport','bus','metro','tramway','train','avion','piste','cyclable','aire','jeu','enfant','enfants'
          'crêche','parentale','haltes','garderies','jardin','d\éveil','assistante maternelle',
          'école maternelle','école élémentaire','collège','lycée professionel','lycée général','lycée technologi',
          'lycée polyvalent','université','fac','campus','étudiant','centre','formation','sport','scolaire',
          'loisir','école','centre','aéré','rythme','péri','extra','MDPH','CDAPH','IME','IEM','ITEP','SESSAD',
          'FAM','SAVS','SAMSAH','ESAT','maladie','mentale','soin','infirmier','CLIC','aidant','EHPAD','alzheimer',
          'pôle','accueil','familial','domicile','agé','CDD','senior','loisir','CHRS','hebergement','urgence','asile',
          'femme','batue','addictologie','desintoxication','insertion','remobilisation','aide','alimentaire','colis',
          'urgence','RSA','ASE','aide','socia','enfan','protection','enfance','CAF','allocation','famill','aide',
          'devoir','soutien','MJC','maison','jeune','majeur','accès','soin','APL','résidence','universitaire',
          'CLE','hebergement','scolaire','mission','locale','Crous','financ','bourse','pharmacie','médicament',
          'santé','hôpita','hospital','clinique','ambulance','formation','sanitaire','toilette','douche',
          'patrimoine','château','exposition','collection','musée','art','contemporain','cinéma','projection','film',
          'télévision','reportage','salsa','tango','danse','hip-hop','bourrée','farandole','rock-and-roll','twist',
          'valse','bal','musette','country','flamenco','concert','hestiv\'oc','musique','hestiv\'oc',
          'opéra','théatre','cirque','artifice','illumination','pyrotechnie','pyromusical','carnaval','urbain','défilé',
          'médiathèque','bibliothèque','livre','lecture','ludothèque','baseball','basket-ball','football',
          'football américain','handball','hockey','pétanque','boulodrome','rugby','volley-ball','athlétisme',
          'ball-trap','poing','billard','snooker','bowling','quille','echec','equitation','cheval','equestre',
          'ecrime','fleuret','epée','gymnastique','musculation','haltérophilie','culturisme','javelot','pentathlon',
          'roller','skate','roulette','pistolet','carabine','arc','triathlo','twirling','majorette','aikido','aikibudo',
          'budo','boxe','ring','savate','full contact','judo','kendo','jujitsu','karaté','martiaux','kick','boxing',
          'lutte','Muaythai','teakwondo','tai','chuan','gong','badminton','tambourin','paume','padel','pelote',
          'pala','squash','tennis','pong','ping','aviron','canöe','kayak','char','voile','plongée','apnée','sous',
          'marin','joute','sauvetage','nautique','motonautique','jetski','natation','nage','piscine','pêche','ski',
          'nautique','surf','voile','aéromodélisme','aéronautique','aérostation','camarguaise','landaise','toromachie',
          'cyclisme','cyclotourisme','giraviation','golf','escalade','motocyclisme','parachutisme','ULM','pédestre',
          'sauvetage','secourisme','ski','spéléologie','automobile','glace','patinage','traineau','pulka','parapente',
          'planeur','état','civil','fiscal','impôt','taxe','administation','numérique','démocratie','participative',
          'participatif','assainissement','ATMO','déchêt','collecte','traitement','déchetterie','recyclage',
          'gendarmerie','commisariat','police','municipale','sécurité','ASVP','SDIS','pompiers','parc','potager',
          'lac','étang','rivière','marais','site','naturel','biodiversité','ENS','forêt','bois','point de vue',
          'table d\'orientation','chemin','pédestre','propre','netto','énergie','chauffage','électricité',
          'écologie','renouvable','durable','environnement','économie','innovation','commerc','artisan',
          'fabication','tourisme','vin','gastronomie','emploi','chômage','job','recrute','entreprise','industrie',
          'entreupreun','création','agricult','agricole','coopération','international']
          
for i in range(len(result_details)):
    # If not already a list:
    text = (''.join(result_details[i])) + (''.join(result_nom[i]))
    delimiter = ' ' 
    #text=''.join(text) #from tuple to string
    text=text.lower() #avoid case
    data_list = text.strip().split()
    most_common_list = Counter(data_list).most_common()
    #print(most_common_list)
     
    mc_dict = dict((x, y) for x, y in most_common_list)
    #print('\n\n\n~~~~~~~~Mots et occurence des mots:')
    #print(mc_dict)
    matches = []
     
    for idx, word in enumerate(MC):
        try:
            count = mc_dict[word]
            matches.append((word, count))
        except:
            continue
    print('\n\n\nIdentifiant et mots clés trouvés')
    if not matches:
        print(result_id[i],':Aucun mot trouvé')
    else:     
        print(result_id[i],matches)
And here is what the result looks like:

Identifiant et mots clés trouvés
(('https://data.datatourisme.gouv.fr/20/d7b292c0-931d-301c-8c7b-4eae0b1bc8e1',), [('rue', 1), ('jardin', 3)])



Identifiant et mots clés trouvés
(('https://data.datatourisme.gouv.fr/20/d7c8ed18-4746-3a01-be47-17ce9534eb86',), [('musique', 2), ('sous', 1)])



Identifiant et mots clés trouvés
(('https://data.datatourisme.gouv.fr/20/d7e7bc31-1fce-3e7c-a7db-82bb3681b315',), ':Aucun mot trouv\xc3\xa9')



Identifiant et mots clés trouvés
(('https://data.datatourisme.gouv.fr/20/d8157157-94e4-3766-8ec0-caac8a0e4623',), [('sport', 1)])
With first the id then the word and its occurence
One last problem i have is that it display non encoded utf-8 character. I've tried many things but nothing seemed to work
Reply


Messages In This Thread
Trying to sort a MYSQL Database - by PierreSoulier - Jul-04-2018, 08:39 AM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-04-2018, 08:51 AM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-04-2018, 09:20 AM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-04-2018, 04:19 PM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-05-2018, 10:23 AM
RE: Trying to sort a MYSQL Database - by PierreSoulier - Jul-05-2018, 01:26 PM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-05-2018, 03:38 PM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-06-2018, 11:14 AM
RE: Trying to sort a MYSQL Database - by micseydel - Jul-14-2018, 03:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 694 Oct-03-2023, 10:25 PM
Last Post: lostintime
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,328 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,149 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  mySQL Database error not resolving. cybertooth 2 3,235 Aug-30-2021, 05:45 PM
Last Post: ibreeden
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,187 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Problem updating value in MySQL database dangermaus33 1 1,646 Nov-24-2020, 08:32 PM
Last Post: dangermaus33
  chatterbot utf-8 errors with mysql database isolatedastronaut 0 1,593 Nov-08-2020, 06:54 AM
Last Post: isolatedastronaut
  MYSQL how to assign a table for each user in my username table database? YoshikageKira 1 2,824 Dec-26-2019, 05:57 AM
Last Post: buran
  How to return value from a stored procedure of a MySQL database? UtiliseIT 0 2,345 Jul-22-2019, 10:14 AM
Last Post: UtiliseIT
  Need help saving data into MySQL database reezalaq 0 2,403 Jun-03-2018, 07:50 PM
Last Post: reezalaq

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020