Click here to Skip to main content
15,887,214 members

Comments by Megan van Bommel (Top 14 by date)

Megan van Bommel 10-Jun-22 9:35am View    
The code is working now in Python, but there were no values loaded. So id is not loading in an another table. This is the code:

# Fact_purchase
for fact_sales in processed_response:
cursor.execute("""
SELECT cinema_id, movie_id, booking_id, date_id
FROM dim_cinema, dim_movie, dim_booking, dim_date
WHERE cinema_name = '"""+cinema_name+"""'
AND cinema_location = '"""+cinema_location+""""'
OR Movie_Distributor = '"""+movie_distributor+"""'
OR Movie_Title = '"""+movie_title+""""'
OR booking_size = '"""+booking_size+"""'
OR booking_age = '"""+booking_age+""""'
OR date_purchase = '"""+date_purchase+"""'
OR date_vacation = '"""+date_vacation+""""'
OR date_week = '"""+date_week+""""'
OR date_month = '"""+date_month+""""'
""")

try:
cursor.execute(sql)
for result in cursor:
bioscoop_id = result['bioscoop_id']
cinema_id= dim_cinema['cinema_id']
movie_id= dim_movie['movie_id']
booking_id= dim_booking['booking_id']
movie_id= dim_movie['movie_id']
db.commit()

except Exception as e:
print(e)
db.rollback()

# Then, we insert the new record in the fact table, together with the values
# Revenue & Costs come from the API call
# Bioscoop_id was retrieved from the dimension table
try:
cursor.execute("INSERT INTO fact_sales (cinema_id, movie_id, booking_id, date_id) VALUES ('"+str(cinema_id)+"', '"+str(movie_id)+"', '"+str(booking_id)+"', '"+str(date_id)+"'")
db.commit()

except Exception as e:
print(e)
db.rollback()
Megan van Bommel 10-Jun-22 8:51am View    
I want to insert the SQL statement above in python. But how can i do that. Because i tried the statement in SQL and that works. But i need that statement in python. How can i covert de SQL statement to a python statement?
Megan van Bommel 10-Jun-22 8:36am View    
Yes but this wasnt working, so can you help me to write a python script that will working or not.
Megan van Bommel 8-Jun-22 11:05am View    
Yes i did that but this an example
Megan van Bommel 8-Jun-22 10:55am View    
Yes, the script is working thank you alot. But how can i make this work. Because every date above 2020-03-01 is "voorjaarsvakantie" but it is not a vacation

date_purchase = "2020-0-01"
date_vacation = "Voorjaarsvakantie"
if "2020-02-15" >= date_purchase <= "2020-03-01":
date_vacation = "No vacation"