import mysql.connector as sql import pandas as pd import re yhendus=sql.connect(host='localhost', database='mart', user='mart', password='ajutine1234') df=pd.read_sql(""" SELECT efis_film.id, title_proper, amount, title FROM efis_film_type INNER JOIN efis_film_type_translation ON efis_film_type_translation.film_type_id=efis_film_type.id INNER JOIN efis_film_type_rel ON efis_film_type.id=efis_film_type_rel.film_type_id INNER JOIN efis_film ON efis_film.id=efis_film_type_rel.film_id INNER JOIN efis_film_translation ON efis_film_translation.film_id=efis_film.id LEFT JOIN efis_film_physical_description ON efis_film_physical_description.film_id=efis_film.id AND (classificator_code2="FILM_PHYSICAL_TYPE_FILM_FILM_DURATION" OR classificator_code2="FILM_PHYSICAL_TYPE_VIDEO_VIDEO_DURATION" OR classificator_code2="FILM_PHYSICAL_TYPE_FILE_FILE_DURATION") WHERE efis_film_translation.language='et' AND title="Täispikk mängufilm"; """, yhendus) #print(df) ajad=df.amount.values.tolist() #print(ajad) aegsek=[] for aeg in ajad: if aeg: andmed=re.findall("^([0-9]{2}):([0-9]{2}):([0-9]{2})$", aeg.strip()) if andmed: aegsek.append(int(andmed[0][0])*3600+int(andmed[0][1])*60+int(andmed[0][2])) else: andmed=re.findall("([0-9]{2,3}):([0-9]{2})", aeg.strip()) if andmed: #print(aeg, andmed[0], andmed[0][0], andmed[0][1]) aegsek.append(int(andmed[0][0])*60+int(andmed[0][1])) else: andmed=re.findall("([0-9]{1,3})[ ]+min", aeg.strip()) if andmed: aegsek.append(int(andmed[0][0])*60) else: print(aeg, "?") else: aegsek.append(0) print(aegsek) print(sum(aegsek))