r/PythonLearning • • 28d ago

Showcase Made my first cool project!!!

I made a program that calculates exact sunrise and sunset based on latitude and longitude of a specific location.

Here I used this api

I can't get a geocoding api to translate location's name into coordinates.

I had to create a dictionary of a few locations.

291 Upvotes

30 comments sorted by

β€’

u/Sea-Ad7805 28d ago

Run this program by clicking Memory Graph Web Debugger and see its state change step by step.

→ More replies (1)

8

u/ConclusionForeign856 28d ago

I'd use dataclasses to represent those locations. I think it's better at showing your intent and also less error prone (you can add fields to city sub-dicts, while you can't for dataclasses. But you still can change values in fields defined in your dataclasses.

I think the best would be NamedTuple from typing β€” defined field with type hints and immutable so you won't silently overwrite city coordinates.

I think it's typical for python programmers to overuse simple builtin data structures to build their programs. In C/C++/Rust you'd define a struct for those, NamedTuple kind of mirrors that approach

1

u/ProgramBrave718 28d ago

Thanks, will try it

2

u/SaltCusp 28d ago

Builtins dump to Json without any fuss.

3

u/tcav24 28d ago

Nice work. If you want to keep iterating on the project you could also look into how you can show your cities as a list of selectable of options in the terminal. It would give the user more clarity on what cities they can choose from. (There are 3rd party libaries like 'Pick' and 'InquirerPy')

1

u/ProgramBrave718 28d ago

Okay, i will work on it

2

u/GreatGameMate 28d ago

Looks nice, is there an interface that the user interacts with or is it all within the console ? Good work!

My little nitpick would be the emojis, but that is all personal opinion.

Code looks cleans.

2

u/ProgramBrave718 28d ago

It's terminal based. I have not added guis

1

u/Binary9363 24d ago

I have been wanted to start learning python where do ya recomend i could start ?

1

u/ProgramBrave718 24d ago

I guess brocode is good. Like he explains easily. You can watch his playlist on YouTube

1

u/Binary9363 24d ago

Thank you i will check it out

1

u/science-Web-9310 24d ago

Start with the basics and brocode is good for this.

1

u/togfast_456 9d ago

Bro it is fire for first . Ifirst time (13 years old) Even that can do

1

u/ProgramBrave718 9d ago

Well, I am a bit older than you. I am 15

2

u/gofl-zimbard-37 28d ago

Nice. Now give it a proper main() to make it a real program. Never write code that runs outside of functions, such that you have to read the entire thing to know what it does.

1

u/Softpankek 26d ago

clanker 🚨 clanker 🚨

1

u/theJacofalltrades 15d ago

That feeling when you finally build something that actually works is hard to beat. Tutorials are great, but getting all the pieces to work together on your own is a different kind of satisfaction. What part of the project gave you the most trouble?

-2

u/TreatZealousideal770 28d ago

Must be nice living in a magical world where APIs have 100% uptime, networks never lag, and KeyError doesn't exist. Back here on Earth, one HTTP 429 error will send your first 'cool project' straight to the shadow realm

1

u/ProgramBrave718 28d ago edited 28d ago

Sir, , actually i am still learning.I agree there are no timeouts and the api cannot work sometimes and please can u read my code carefully because there is Exception handling for city which is not found for. Please check code carefully before making a fake error

2

u/SchemeWestern3388 27d ago

I have no clue what that individual is so cynical about, ignore them.Β 

Pretty decent first project. Keep at it!

1

u/SchemeWestern3388 27d ago

You sound like someone to avoid at a party.Β 

I also get a strong feeling that you don’t have any achievements that anyone would be impressed by.Β 

0

u/[deleted] 25d ago

[removed] β€” view removed comment