Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Program Real Time Traffic using ML algorithm #60

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Movie Scraper/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ def getMovieDetails(movieName:str):
i.text for i in box_two.select('div.ipc-chip-list__scroller>a>span')]

# Fix ratings
try:
movieDetails['rating'] = f"{bs.find(
'div', {'data-testid': 'hero-rating-bar__aggregate-rating__score'}).span.text}/10 ({bs.find('div', {'class': 'sc-bde20123-3 gPVQxL'}).text})"
movieDetails['runtime'] = box[2].text.strip()
except AttributeError:
movieDetails['rating'] = 'Not yet rated'
movieDetails['runtime'] = 'Not available'

try:
movieDetails['rating'] = f"{bs.find('div', {'data-testid': 'hero-rating-bar__aggregate-rating__score'}).span.text}/10 ({bs.find('div', {'class': 'sc-bde20123-3 gPVQxL'}).text})"
movieDetails['runtime'] = box[2].text.strip()
except AttributeError:
movieDetails['rating'] = 'Not yet rated'
movieDetails['runtime'] = 'Not available'


# To get movie release date
movie_release_dates_url= f"{url}{box[0].a.attrs['href']}"
Expand Down
69 changes: 69 additions & 0 deletions Real Time Traffic/main-ml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 1. Set your API key.
# 2. Specify the location for traffic data.
# 3. Ensure the CSV file is correctly formatted with the expected columns for features and target.
# feature1 feature2 target
# 1.2 3.4 5
# 2.1 4.5 6
# 1.8 3.6 4



import requests
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import folium

# Function to fetch real-time traffic data
def get_traffic_data(location):
api_key = "YOUR_API_KEY" # Replace with your actual API key
url = f"https://api.trafficapi.com/v1/traffic?location={location}&key={api_key}"
response = requests.get(url)
return response.json()

# Function to train a machine learning model
def train_model(data):
# Sample DataFrame structure; replace with actual features and target
X = data[['feature1', 'feature2']] # Adjust as necessary
y = data['target'] # Adjust as necessary

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = LinearRegression()
model.fit(X_train, y_train)
return model

# Function to visualize traffic data on a map
def visualize_traffic(data):
# Create a map centered around the location
m = folium.Map(location=[data['latitude'], data['longitude']], zoom_start=12)

for incident in data['incidents']:
folium.Marker(
location=[incident['lat'], incident['lng']],
popup=incident['description'],
icon=folium.Icon(color='red')
).add_to(m)

return m

# Main function to tie everything together
def main(location):
# Fetch real-time traffic data
traffic_data = get_traffic_data(location)

# Load historical data for model training (replace with actual loading logic)
historical_data = pd.read_csv('historical_traffic_data.csv') # Placeholder
model = train_model(historical_data)

# Predict traffic using the model
predicted_traffic = model.predict(traffic_data[['feature1', 'feature2']]) # Adjust features

# Visualize the traffic on a map
map_with_traffic = visualize_traffic(traffic_data)

map_with_traffic.save("traffic_map.html")
print("Traffic map saved as traffic_map.html")

if __name__ == "__main__":
location = "Your_Location_Here" # Replace with actual location
main(location)
49 changes: 49 additions & 0 deletions Real Time Traffic/pure python code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import requests
import folium

# Function to fetch real-time traffic data based on GPS coordinates
def get_traffic_data(lat, lng):
api_key = "YOUR_API_KEY" # Replace with your actual API key
url = f"https://api.trafficapi.com/v1/traffic?latitude={lat}&longitude={lng}&key={api_key}"

try:
response = requests.get(url)
response.raise_for_status()
return response.json() # Returns JSON response
except requests.exceptions.RequestException as e:
print(f"Error fetching traffic data: {e}")
return None

# Function to visualize traffic data on a map
def visualize_traffic(data, lat, lng):
# Create a map centered around the given GPS coordinates
m = folium.Map(location=[lat, lng], zoom_start=12)

# Check if traffic data exists
if data and "incidents" in data:
for incident in data['incidents']:
folium.Marker(
location=[incident['lat'], incident['lng']],
popup=incident['description'],
icon=folium.Icon(color='red')
).add_to(m)
else:
print("No traffic incidents found.")

# Save the map to an HTML file
m.save("traffic_map.html")
print("Traffic map saved as traffic_map.html")

def main():
# Example GPS coordinates (latitude, longitude)
lat = 37.7749 # Replace with your latitude
lng = -122.4194 # Replace with your longitude

# Fetch real-time traffic data
traffic_data = get_traffic_data(lat, lng)

# Visualize the traffic on a map
visualize_traffic(traffic_data, lat, lng)

if __name__ == "__main__":
main()
Binary file added Real Time Traffic/requirements.txt
Binary file not shown.
1 change: 1 addition & 0 deletions Real Time Traffic/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.10.7
80 changes: 80 additions & 0 deletions quote_list.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
quote,author,tags
“The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking.”,Albert Einstein,"['change', 'deep-thoughts', 'thinking', 'world']"
"“It is our choices, Harry, that show what we truly are, far more than our abilities.”",J.K. Rowling,"['abilities', 'choices']"
“There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.”,Albert Einstein,"['inspirational', 'life', 'live', 'miracle', 'miracles']"
"“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.”",Jane Austen,"['aliteracy', 'books', 'classic', 'humor']"
"“Imperfection is beauty, madness is genius and it's better to be absolutely ridiculous than absolutely boring.”",Marilyn Monroe,"['be-yourself', 'inspirational']"
“Try not to become a man of success. Rather become a man of value.”,Albert Einstein,"['adulthood', 'success', 'value']"
“It is better to be hated for what you are than to be loved for what you are not.”,André Gide,"['life', 'love']"
"“I have not failed. I've just found 10,000 ways that won't work.”",Thomas A. Edison,"['edison', 'failure', 'inspirational', 'paraphrased']"
“A woman is like a tea bag; you never know how strong it is until it's in hot water.”,Eleanor Roosevelt,['misattributed-eleanor-roosevelt']
"“A day without sunshine is like, you know, night.”",Steve Martin,"['humor', 'obvious', 'simile']"
"“This life is what you make it. No matter what, you're going to mess up sometimes, it's a universal truth. But the good part is you get to decide how you're going to mess it up. Girls will be your friends - they'll act like it anyway. But just remember, some come, some go. The ones that stay with you through everything - they're your true best friends. Don't let go of them. Also remember, sisters make the best friends in the world. As for lovers, well, they'll come and go too. And baby, I hate to say it, most of them - actually pretty much all of them are going to break your heart, but you can't give up because if you give up, you'll never find your soulmate. You'll never find that half who makes you whole and that goes for everything. Just because you fail once, doesn't mean you're gonna fail at everything. Keep trying, hold on, and always, always, always believe in yourself, because if you don't, then who will, sweetie? So keep your head high, keep your chin up, and most importantly, keep smiling, because life's a beautiful thing and there's so much to smile about.”",Marilyn Monroe,"['friends', 'heartbreak', 'inspirational', 'life', 'love', 'sisters']"
"“It takes a great deal of bravery to stand up to our enemies, but just as much to stand up to our friends.”",J.K. Rowling,"['courage', 'friends']"
"“If you can't explain it to a six year old, you don't understand it yourself.”",Albert Einstein,"['simplicity', 'understand']"
"“You may not be her first, her last, or her only. She loved before she may love again. But if she loves you now, what else matters? She's not perfect—you aren't either, and the two of you may never be perfect together but if she can make you laugh, cause you to think twice, and admit to being human and making mistakes, hold onto her and give her the most you can. She may not be thinking about you every second of the day, but she will give you a part of her that she knows you can break—her heart. So don't hurt her, don't change her, don't analyze and don't expect more than she can give. Smile when she makes you happy, let her know when she makes you mad, and miss her when she's not there.”",Bob Marley,['love']
"“I like nonsense, it wakes up the brain cells. Fantasy is a necessary ingredient in living.”",Dr. Seuss,['fantasy']
"“I may not have gone where I intended to go, but I think I have ended up where I needed to be.”",Douglas Adams,"['life', 'navigation']"
"“The opposite of love is not hate, it's indifference. The opposite of art is not ugliness, it's indifference. The opposite of faith is not heresy, it's indifference. And the opposite of life is not death, it's indifference.”",Elie Wiesel,"['activism', 'apathy', 'hate', 'indifference', 'inspirational', 'love', 'opposite', 'philosophy']"
"“It is not a lack of love, but a lack of friendship that makes unhappy marriages.”",Friedrich Nietzsche,"['friendship', 'lack-of-friendship', 'lack-of-love', 'love', 'marriage', 'unhappy-marriage']"
"“Good friends, good books, and a sleepy conscience: this is the ideal life.”",Mark Twain,"['books', 'contentment', 'friends', 'friendship', 'life']"
“Life is what happens to us while we are making other plans.”,Allen Saunders,"['fate', 'life', 'misattributed-john-lennon', 'planning', 'plans']"
"“I love you without knowing how, or when, or from where. I love you simply, without problems or pride: I love you in this way because I do not know any other way of loving but this, in which there is no I or you, so intimate that your hand upon my chest is my hand, so intimate that when I fall asleep your eyes close.”",Pablo Neruda,"['love', 'poetry']"
“For every minute you are angry you lose sixty seconds of happiness.”,Ralph Waldo Emerson,['happiness']
"“If you judge people, you have no time to love them.”",Mother Teresa,['attributed-no-source']
“Anyone who thinks sitting in church can make you a Christian must also think that sitting in a garage can make you a car.”,Garrison Keillor,"['humor', 'religion']"
“Beauty is in the eye of the beholder and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.”,Jim Henson,['humor']
"“Today you are You, that is truer than true. There is no one alive who is Youer than You.”",Dr. Seuss,"['comedy', 'life', 'yourself']"
"“If you want your children to be intelligent, read them fairy tales. If you want them to be more intelligent, read them more fairy tales.”",Albert Einstein,"['children', 'fairy-tales']"
"“It is impossible to live without failing at something, unless you live so cautiously that you might as well not have lived at all - in which case, you fail by default.”",J.K. Rowling,[]
“Logic will get you from A to Z; imagination will get you everywhere.”,Albert Einstein,['imagination']
"“One good thing about music, when it hits you, you feel no pain.”",Bob Marley,['music']
"“The more that you read, the more things you will know. The more that you learn, the more places you'll go.”",Dr. Seuss,"['learning', 'reading', 'seuss']"
"“Of course it is happening inside your head, Harry, but why on earth should that mean that it is not real?”",J.K. Rowling,['dumbledore']
"“The truth is, everyone is going to hurt you. You just got to find the ones worth suffering for.”",Bob Marley,['friendship']
“Not all of us can do great things. But we can do small things with great love.”,Mother Teresa,"['misattributed-to-mother-teresa', 'paraphrased']"
"“To the well-organized mind, death is but the next great adventure.”",J.K. Rowling,"['death', 'inspirational']"
“All you need is love. But a little chocolate now and then doesn't hurt.”,Charles M. Schulz,"['chocolate', 'food', 'humor']"
“We read to know we're not alone.”,William Nicholson,"['misattributed-to-c-s-lewis', 'reading']"
“Any fool can know. The point is to understand.”,Albert Einstein,"['knowledge', 'learning', 'understanding', 'wisdom']"
“I have always imagined that Paradise will be a kind of library.”,Jorge Luis Borges,"['books', 'library']"
“It is never too late to be what you might have been.”,George Eliot,['inspirational']
"“A reader lives a thousand lives before he dies, said Jojen. The man who never reads lives only one.”",George R.R. Martin,"['read', 'readers', 'reading', 'reading-books']"
“You can never get a cup of tea large enough or a book long enough to suit me.”,C.S. Lewis,"['books', 'inspirational', 'reading', 'tea']"
“You believe lies so you eventually learn to trust no one but yourself.”,Marilyn Monroe,[]
"“If you can make a woman laugh, you can make her do anything.”",Marilyn Monroe,"['girls', 'love']"
"“Life is like riding a bicycle. To keep your balance, you must keep moving.”",Albert Einstein,"['life', 'simile']"
“The real lover is the man who can thrill you by kissing your forehead or smiling into your eyes or just staring into space.”,Marilyn Monroe,['love']
"“A wise girl kisses but doesn't love, listens but doesn't believe, and leaves before she is left.”",Marilyn Monroe,['attributed-no-source']
“Only in the darkness can you see the stars.”,Martin Luther King Jr.,"['hope', 'inspirational']"
"“It matters not what someone is born, but what they grow to be.”",J.K. Rowling,['dumbledore']
"“Love does not begin and end the way we seem to think it does. Love is a battle, love is a war; love is a growing up.”",James Baldwin,['love']
"“There is nothing I would not do for those who are really my friends. I have no notion of loving people by halves, it is not my nature.”",Jane Austen,"['friendship', 'love']"
“Do one thing every day that scares you.”,Eleanor Roosevelt,"['attributed', 'fear', 'inspiration']"
"“I am good, but not an angel. I do sin, but I am not the devil. I am just a small girl in a big world trying to find someone to love.”",Marilyn Monroe,['attributed-no-source']
"“If I were not a physicist, I would probably be a musician. I often think in music. I live my daydreams in music. I see my life in terms of music.”",Albert Einstein,['music']
"“If you only read the books that everyone else is reading, you can only think what everyone else is thinking.”",Haruki Murakami,"['books', 'thought']"
“The difference between genius and stupidity is: genius has its limits.”,Alexandre Dumas fils,['misattributed-to-einstein']
"“He's like a drug for you, Bella.”",Stephenie Meyer,"['drug', 'romance', 'simile']"
“There is no friend as loyal as a book.”,Ernest Hemingway,"['books', 'friends', 'novelist-quotes']"
"“When one door of happiness closes, another opens; but often we look so long at the closed door that we do not see the one which has been opened for us.”",Helen Keller,['inspirational']
“Life isn't about finding yourself. Life is about creating yourself.”,George Bernard Shaw,"['inspirational', 'life', 'yourself']"
"“That's the problem with drinking, I thought, as I poured myself a drink. If something bad happens you drink in an attempt to forget; if something good happens you drink in order to celebrate; and if nothing happens you drink to make something happen.”",Charles Bukowski,['alcohol']
“You don’t forget the face of the person who was your last hope.”,Suzanne Collins,['the-hunger-games']
"“Remember, we're madly in love, so it's all right to kiss me anytime you feel like it.”",Suzanne Collins,['humor']
"“To love at all is to be vulnerable. Love anything and your heart will be wrung and possibly broken. If you want to make sure of keeping it intact you must give it to no one, not even an animal. Wrap it carefully round with hobbies and little luxuries; avoid all entanglements. Lock it up safe in the casket or coffin of your selfishness. But in that casket, safe, dark, motionless, airless, it will change. It will not be broken; it will become unbreakable, impenetrable, irredeemable. To love is to be vulnerable.”",C.S. Lewis,['love']
“Not all those who wander are lost.”,J.R.R. Tolkien,"['bilbo', 'journey', 'lost', 'quest', 'travel', 'wander']"
"“Do not pity the dead, Harry. Pity the living, and, above all those who live without love.”",J.K. Rowling,['live-death-love']
“There is nothing to writing. All you do is sit down at a typewriter and bleed.”,Ernest Hemingway,"['good', 'writing']"
“Finish each day and be done with it. You have done what you could. Some blunders and absurdities no doubt crept in; forget them as soon as you can. Tomorrow is a new day. You shall begin it serenely and with too high a spirit to be encumbered with your old nonsense.”,Ralph Waldo Emerson,"['life', 'regrets']"
“I have never let my schooling interfere with my education.”,Mark Twain,['education']
“I have heard there are troubles of more than one kind. Some come from ahead and some come from behind. But I've bought a big bat. I'm all ready you see. Now my troubles are going to have troubles with me!”,Dr. Seuss,['troubles']
“If I had a flower for every time I thought of you...I could walk through my garden forever.”,Alfred Tennyson,"['friendship', 'love']"
“Some people never go crazy. What truly horrible lives they must lead.”,Charles Bukowski,['humor']
"“The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.”",Terry Pratchett,"['humor', 'open-mind', 'thinking']"
"“Think left and think right and think low and think high. Oh, the thinks you can think up if only you try!”",Dr. Seuss,"['humor', 'philosophy']"
"“What really knocks me out is a book that, when you're all done reading it, you wish the author that wrote it was a terrific friend of yours and you could call him up on the phone whenever you felt like it. That doesn't happen much, though.”",J.D. Salinger,"['authors', 'books', 'literature', 'reading', 'writing']"
“The reason I talk to myself is because I’m the only one whose answers I accept.”,George Carlin,"['humor', 'insanity', 'lies', 'lying', 'self-indulgence', 'truth']"
"“You may say I'm a dreamer, but I'm not the only one. I hope someday you'll join us. And the world will live as one.”",John Lennon,"['beatles', 'connection', 'dreamers', 'dreaming', 'dreams', 'hope', 'inspirational', 'peace']"
“I am free of all prejudice. I hate everyone equally. ”,W.C. Fields,"['humor', 'sinister']"
“The question isn't who is going to let me; it's who is going to stop me.”,Ayn Rand,[]
Expand Down
Loading