15,887,214 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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"
Megan van Bommel
8-Jun-22 5:41am
View
Yes I use the insert statement down under in my script to insert the value into sql
Megan van Bommel
7-Jun-22 1:06am
View
So can you make the correct code for me than, because this is not working the value is still zero. It’s an school project 😀
Megan van Bommel
6-Jun-22 15:59pm
View
But I need to convert the date_purchase because it is an string format and not an date format
Megan van Bommel
6-Jun-22 15:59pm
View
Dim_date is the name of the table
Megan van Bommel
6-Jun-22 15:58pm
View
the date_purchase will return like 12/31/2020
Megan van Bommel
6-Jun-22 15:37pm
View
And how can i get the month of date_purchase?
Megan van Bommel
6-Jun-22 10:27am
View
Now i get the error: descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'str' object.
This is the code:
for dim_date in processed_response:
# "date" dimension
date = (dim_date["purchase_date"])
date_purchase = str(dim_date["purchase_date"])
if date_purchase == None:
continue
date_week = datetime.datetime.strftime(date_purchase, "%m/%d/%Y")
date_month = datetime.datetime.strftime(date_purchase, "%m/%d/%Y")
if date_week == None:
continue
elif date_month == None:
continue
print(date_purchase, date_week, date_month)
# Check whether this record already exists in the dimension we created.
cursor.execute("""
SELECT * FROM dim_date
WHERE date_purchase = '"""+date_purchase+"""'
AND date_week = '"""+date_week+""""'
AND date_month = '"""+date_month+"""'
""")
# We do this, because we don't have to insert it twice.
sql = """
INSERT INTO dim_date (date_purchase, date_week, date_month)
VALUES ('"""+date_purchase+"""', '"""+date_week+"""', '"""+date_month+"""')
"""
Megan van Bommel
6-Jun-22 6:39am
View
A thnx, I will try that. I let you know if it’s working or not.
Megan van Bommel
6-Jun-22 6:28am
View
Where does I need to put the dateline. Stratum’s. I did that at print but that didn’t work. So I think that position is not the right place?
Show More