How can I improve the code in this Python project? /u/GrizzyLizz Python Education

How can I improve the code in this Python project? /u/GrizzyLizz Python Education

Link: https://gitlab.com/__muditj__/gmail-cli-automation-tool

So I was given an assignment task for hiring and I ended up rushing through it a little so I didnt do so well. The task was: Given a rules.json file which defines certain filters for emails based on different fields like From, Subject, Content etc, filter out the emails which obey the rules and apply the specified actions on them. This is a CLI application where I make use of OAuth2 to authenticate with Google’s Gmail API

I am aware that there are excessive print statements and I dont have any unit tests added but apart from this, in what other ways can I improve the codebase? In particular, I want to know what would be the ideal way to package this application. This was meant to be a CLI application which should be runnable as a script so I have two particular Python files with a “if __name__ == “__main__” block inside them. One is to authenticate with Google OAuth and get the access and refresh token and the other is to run the main part of the application which does the filtering of the emails and applies the specified actions.

submitted by /u/GrizzyLizz
[link] [comments]

​r/learnpython Link: https://gitlab.com/__muditj__/gmail-cli-automation-tool So I was given an assignment task for hiring and I ended up rushing through it a little so I didnt do so well. The task was: Given a rules.json file which defines certain filters for emails based on different fields like From, Subject, Content etc, filter out the emails which obey the rules and apply the specified actions on them. This is a CLI application where I make use of OAuth2 to authenticate with Google’s Gmail API I am aware that there are excessive print statements and I dont have any unit tests added but apart from this, in what other ways can I improve the codebase? In particular, I want to know what would be the ideal way to package this application. This was meant to be a CLI application which should be runnable as a script so I have two particular Python files with a “if __name__ == “__main__” block inside them. One is to authenticate with Google OAuth and get the access and refresh token and the other is to run the main part of the application which does the filtering of the emails and applies the specified actions. submitted by /u/GrizzyLizz [link] [comments] 

Link: https://gitlab.com/__muditj__/gmail-cli-automation-tool

So I was given an assignment task for hiring and I ended up rushing through it a little so I didnt do so well. The task was: Given a rules.json file which defines certain filters for emails based on different fields like From, Subject, Content etc, filter out the emails which obey the rules and apply the specified actions on them. This is a CLI application where I make use of OAuth2 to authenticate with Google’s Gmail API

I am aware that there are excessive print statements and I dont have any unit tests added but apart from this, in what other ways can I improve the codebase? In particular, I want to know what would be the ideal way to package this application. This was meant to be a CLI application which should be runnable as a script so I have two particular Python files with a “if __name__ == “__main__” block inside them. One is to authenticate with Google OAuth and get the access and refresh token and the other is to run the main part of the application which does the filtering of the emails and applies the specified actions.

submitted by /u/GrizzyLizz
[link] [comments]  Link: https://gitlab.com/__muditj__/gmail-cli-automation-tool So I was given an assignment task for hiring and I ended up rushing through it a little so I didnt do so well. The task was: Given a rules.json file which defines certain filters for emails based on different fields like From, Subject, Content etc, filter out the emails which obey the rules and apply the specified actions on them. This is a CLI application where I make use of OAuth2 to authenticate with Google’s Gmail API I am aware that there are excessive print statements and I dont have any unit tests added but apart from this, in what other ways can I improve the codebase? In particular, I want to know what would be the ideal way to package this application. This was meant to be a CLI application which should be runnable as a script so I have two particular Python files with a “if __name__ == “__main__” block inside them. One is to authenticate with Google OAuth and get the access and refresh token and the other is to run the main part of the application which does the filtering of the emails and applies the specified actions. submitted by /u/GrizzyLizz [link] [comments]

Read more

Python library documentation /u/Classic_essays Python Education

Python library documentation /u/Classic_essays Python Education

Hello guys.

I’m working on an opensource library and I need to start documenting it. I will use Readthedocs for hosting.

However, I’m caught between using mkdocs and sphnix. Any advice on this would be greatly appreciated.

Thanks

submitted by /u/Classic_essays
[link] [comments]

​r/learnpython Hello guys. I’m working on an opensource library and I need to start documenting it. I will use Readthedocs for hosting. However, I’m caught between using mkdocs and sphnix. Any advice on this would be greatly appreciated. Thanks submitted by /u/Classic_essays [link] [comments] 

Hello guys.

I’m working on an opensource library and I need to start documenting it. I will use Readthedocs for hosting.

However, I’m caught between using mkdocs and sphnix. Any advice on this would be greatly appreciated.

Thanks

submitted by /u/Classic_essays
[link] [comments]  Hello guys. I’m working on an opensource library and I need to start documenting it. I will use Readthedocs for hosting. However, I’m caught between using mkdocs and sphnix. Any advice on this would be greatly appreciated. Thanks submitted by /u/Classic_essays [link] [comments]

Read more

How bad is this method of getting Even/Odd? /u/VanClyded Python Education

How bad is this method of getting Even/Odd? /u/VanClyded Python Education

Been getting back into Python and i needed to find even/odd numbers in a short list, came up with a ridiculous line of code that seem… to work?
Example using said line of code;

num = input(“Number: “) if float(num)/2 – int(int(num)/2) == 0: print(“EVEN”) else: print(“ODD”)

So my question is, am i just lucky or is this a *appropriate* way to get this?

submitted by /u/VanClyded
[link] [comments]

​r/learnpython Been getting back into Python and i needed to find even/odd numbers in a short list, came up with a ridiculous line of code that seem… to work? Example using said line of code; num = input(“Number: “) if float(num)/2 – int(int(num)/2) == 0: print(“EVEN”) else: print(“ODD”) So my question is, am i just lucky or is this a *appropriate* way to get this? submitted by /u/VanClyded [link] [comments] 

Been getting back into Python and i needed to find even/odd numbers in a short list, came up with a ridiculous line of code that seem… to work?
Example using said line of code;

num = input(“Number: “) if float(num)/2 – int(int(num)/2) == 0: print(“EVEN”) else: print(“ODD”)

So my question is, am i just lucky or is this a *appropriate* way to get this?

submitted by /u/VanClyded
[link] [comments]  Been getting back into Python and i needed to find even/odd numbers in a short list, came up with a ridiculous line of code that seem… to work? Example using said line of code; num = input(“Number: “) if float(num)/2 – int(int(num)/2) == 0: print(“EVEN”) else: print(“ODD”) So my question is, am i just lucky or is this a *appropriate* way to get this? submitted by /u/VanClyded [link] [comments]

Read more

Help with making a computer for school project /u/deathnote9 Python Education

Help with making a computer for school project /u/deathnote9 Python Education

My connect 4 program is in two files below. So I have to make a computer that drops random spots unless it has a winning play. I got the random part down but not sure how to get the second part. Any help would be appreciated.

https://pastebin.com/dsCeAbTP

https://pastebin.com/2PqcJus0

submitted by /u/deathnote9
[link] [comments]

​r/learnpython My connect 4 program is in two files below. So I have to make a computer that drops random spots unless it has a winning play. I got the random part down but not sure how to get the second part. Any help would be appreciated. https://pastebin.com/dsCeAbTP https://pastebin.com/2PqcJus0 submitted by /u/deathnote9 [link] [comments] 

My connect 4 program is in two files below. So I have to make a computer that drops random spots unless it has a winning play. I got the random part down but not sure how to get the second part. Any help would be appreciated.

https://pastebin.com/dsCeAbTP

https://pastebin.com/2PqcJus0

submitted by /u/deathnote9
[link] [comments]  My connect 4 program is in two files below. So I have to make a computer that drops random spots unless it has a winning play. I got the random part down but not sure how to get the second part. Any help would be appreciated. https://pastebin.com/dsCeAbTP https://pastebin.com/2PqcJus0 submitted by /u/deathnote9 [link] [comments]

Read more

Where to learn project organization? /u/Waveover Python Education

Where to learn project organization? /u/Waveover Python Education

I’m getting to the point where I am building bigger projects in python now, but after a while the project becomes too big that I find it too much work to make any new changes and leave the project as is for long periods of time.

Where can I learn how to structure my projects better so that even as my project grows I can keep working on it? To add some context I would consider myself a bit above beginner. I am able to create different files and seperate out my code into functions and try keep modules cohesively tight. I don’t really use classes though. I wonder if that is the big issue for me. Or its more of high level concepts as far as organizing and structuring my code that I need to learn as a developer.

What or where should I learn to make that next step?

submitted by /u/Waveover
[link] [comments]

​r/learnpython I’m getting to the point where I am building bigger projects in python now, but after a while the project becomes too big that I find it too much work to make any new changes and leave the project as is for long periods of time. Where can I learn how to structure my projects better so that even as my project grows I can keep working on it? To add some context I would consider myself a bit above beginner. I am able to create different files and seperate out my code into functions and try keep modules cohesively tight. I don’t really use classes though. I wonder if that is the big issue for me. Or its more of high level concepts as far as organizing and structuring my code that I need to learn as a developer. What or where should I learn to make that next step? submitted by /u/Waveover [link] [comments] 

I’m getting to the point where I am building bigger projects in python now, but after a while the project becomes too big that I find it too much work to make any new changes and leave the project as is for long periods of time.

Where can I learn how to structure my projects better so that even as my project grows I can keep working on it? To add some context I would consider myself a bit above beginner. I am able to create different files and seperate out my code into functions and try keep modules cohesively tight. I don’t really use classes though. I wonder if that is the big issue for me. Or its more of high level concepts as far as organizing and structuring my code that I need to learn as a developer.

What or where should I learn to make that next step?

submitted by /u/Waveover
[link] [comments]  I’m getting to the point where I am building bigger projects in python now, but after a while the project becomes too big that I find it too much work to make any new changes and leave the project as is for long periods of time. Where can I learn how to structure my projects better so that even as my project grows I can keep working on it? To add some context I would consider myself a bit above beginner. I am able to create different files and seperate out my code into functions and try keep modules cohesively tight. I don’t really use classes though. I wonder if that is the big issue for me. Or its more of high level concepts as far as organizing and structuring my code that I need to learn as a developer. What or where should I learn to make that next step? submitted by /u/Waveover [link] [comments]

Read more

my code runs forever, unless i restart session /u/qhelspil Python Education

my code runs forever, unless i restart session /u/qhelspil Python Education

when i restart session, my code runs hte amoun tof time i specified, its like that for couple of times, until it keeps runnin forever without stopping.

this is the source of my code, i jusst made little changes ( adding path)

this snippet sometimes runs 3 seconds, sometimes forever

RECORD = “”” const sleep = time => new Promise(resolve => setTimeout(resolve, time)) const b2text = blob => new Promise(resolve => { const reader = new FileReader() reader.onloadend = e => resolve(e.srcElement.result) reader.readAsDataURL(blob) }) var record = time => new Promise(async resolve => { stream = await navigator.mediaDevices.getUserMedia({ audio: true }) recorder = new MediaRecorder(stream) chunks = [] recorder.ondataavailable = e => chunks.push(e.data) recorder.start() await sleep(time) recorder.onstop = async ()=>{ blob = new Blob(chunks) text = await b2text(blob) resolve(text) } recorder.stop() }) “”” def record_audio(sec,path): display(Javascript(RECORD)) s = output.eval_js(‘record(%d)’ % (sec*1000)) b = b64decode(s.split(‘,’)[1]) audio = AudioSegment.from_file(BytesIO(b)) audio.export(path, format=’wav’) return audio record_audio(3,’output1.wav’)

this snippet runs forever, idk why

import threading thread1 = threading.Thread(target=record_audio, args=([3,’output2.wav’])) thread2 = threading.Thread(target=record_audio, args=([3,’output3.wav’])) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”)

why is that?

submitted by /u/qhelspil
[link] [comments]

​r/learnpython when i restart session, my code runs hte amoun tof time i specified, its like that for couple of times, until it keeps runnin forever without stopping. this is the source of my code, i jusst made little changes ( adding path) this snippet sometimes runs 3 seconds, sometimes forever RECORD = “”” const sleep = time => new Promise(resolve => setTimeout(resolve, time)) const b2text = blob => new Promise(resolve => { const reader = new FileReader() reader.onloadend = e => resolve(e.srcElement.result) reader.readAsDataURL(blob) }) var record = time => new Promise(async resolve => { stream = await navigator.mediaDevices.getUserMedia({ audio: true }) recorder = new MediaRecorder(stream) chunks = [] recorder.ondataavailable = e => chunks.push(e.data) recorder.start() await sleep(time) recorder.onstop = async ()=>{ blob = new Blob(chunks) text = await b2text(blob) resolve(text) } recorder.stop() }) “”” def record_audio(sec,path): display(Javascript(RECORD)) s = output.eval_js(‘record(%d)’ % (sec*1000)) b = b64decode(s.split(‘,’)[1]) audio = AudioSegment.from_file(BytesIO(b)) audio.export(path, format=’wav’) return audio record_audio(3,’output1.wav’) this snippet runs forever, idk why import threading thread1 = threading.Thread(target=record_audio, args=([3,’output2.wav’])) thread2 = threading.Thread(target=record_audio, args=([3,’output3.wav’])) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”) why is that? submitted by /u/qhelspil [link] [comments] 

when i restart session, my code runs hte amoun tof time i specified, its like that for couple of times, until it keeps runnin forever without stopping.

this is the source of my code, i jusst made little changes ( adding path)

this snippet sometimes runs 3 seconds, sometimes forever

RECORD = “”” const sleep = time => new Promise(resolve => setTimeout(resolve, time)) const b2text = blob => new Promise(resolve => { const reader = new FileReader() reader.onloadend = e => resolve(e.srcElement.result) reader.readAsDataURL(blob) }) var record = time => new Promise(async resolve => { stream = await navigator.mediaDevices.getUserMedia({ audio: true }) recorder = new MediaRecorder(stream) chunks = [] recorder.ondataavailable = e => chunks.push(e.data) recorder.start() await sleep(time) recorder.onstop = async ()=>{ blob = new Blob(chunks) text = await b2text(blob) resolve(text) } recorder.stop() }) “”” def record_audio(sec,path): display(Javascript(RECORD)) s = output.eval_js(‘record(%d)’ % (sec*1000)) b = b64decode(s.split(‘,’)[1]) audio = AudioSegment.from_file(BytesIO(b)) audio.export(path, format=’wav’) return audio record_audio(3,’output1.wav’)

this snippet runs forever, idk why

import threading thread1 = threading.Thread(target=record_audio, args=([3,’output2.wav’])) thread2 = threading.Thread(target=record_audio, args=([3,’output3.wav’])) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”)

why is that?

submitted by /u/qhelspil
[link] [comments]  when i restart session, my code runs hte amoun tof time i specified, its like that for couple of times, until it keeps runnin forever without stopping. this is the source of my code, i jusst made little changes ( adding path) this snippet sometimes runs 3 seconds, sometimes forever RECORD = “”” const sleep = time => new Promise(resolve => setTimeout(resolve, time)) const b2text = blob => new Promise(resolve => { const reader = new FileReader() reader.onloadend = e => resolve(e.srcElement.result) reader.readAsDataURL(blob) }) var record = time => new Promise(async resolve => { stream = await navigator.mediaDevices.getUserMedia({ audio: true }) recorder = new MediaRecorder(stream) chunks = [] recorder.ondataavailable = e => chunks.push(e.data) recorder.start() await sleep(time) recorder.onstop = async ()=>{ blob = new Blob(chunks) text = await b2text(blob) resolve(text) } recorder.stop() }) “”” def record_audio(sec,path): display(Javascript(RECORD)) s = output.eval_js(‘record(%d)’ % (sec*1000)) b = b64decode(s.split(‘,’)[1]) audio = AudioSegment.from_file(BytesIO(b)) audio.export(path, format=’wav’) return audio record_audio(3,’output1.wav’) this snippet runs forever, idk why import threading thread1 = threading.Thread(target=record_audio, args=([3,’output2.wav’])) thread2 = threading.Thread(target=record_audio, args=([3,’output3.wav’])) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”) why is that? submitted by /u/qhelspil [link] [comments]

Read more

Matplotlib – Secondary axis lacks anti-aliasing? /u/Thunderflower58 Python Education

Matplotlib – Secondary axis lacks anti-aliasing? /u/Thunderflower58 Python Education

Hi everybody, I didn’t find anything on this problem while searching the web. When adding a second x-axis to my plots, the secondary axis seems to lack anti-aliasing or sth (it just looks weirdly bold and pixelated). The secondary axis is added with ax.secondary_xaxis. I plan to export these as .svg and depending on the scaling it just looks awful (they also look bad as .png). The other side of the x-axis looks fine.

Does anyone have an idea as to what could be causing this? I am using Matplotlib 3.4.3 and Python 3.9.7.

(So far I haven’t been able to reproduce this behaviour in a MWE and otherwise it would be a hole load of code and data)

Edit: It seems that my image wasn’t uploaded with the post, trying to fix it…

Image: https://imgur.com/a/aadLbpO

submitted by /u/Thunderflower58
[link] [comments]

​r/learnpython Hi everybody, I didn’t find anything on this problem while searching the web. When adding a second x-axis to my plots, the secondary axis seems to lack anti-aliasing or sth (it just looks weirdly bold and pixelated). The secondary axis is added with ax.secondary_xaxis. I plan to export these as .svg and depending on the scaling it just looks awful (they also look bad as .png). The other side of the x-axis looks fine. Does anyone have an idea as to what could be causing this? I am using Matplotlib 3.4.3 and Python 3.9.7. (So far I haven’t been able to reproduce this behaviour in a MWE and otherwise it would be a hole load of code and data) Edit: It seems that my image wasn’t uploaded with the post, trying to fix it… Image: https://imgur.com/a/aadLbpO submitted by /u/Thunderflower58 [link] [comments] 

Hi everybody, I didn’t find anything on this problem while searching the web. When adding a second x-axis to my plots, the secondary axis seems to lack anti-aliasing or sth (it just looks weirdly bold and pixelated). The secondary axis is added with ax.secondary_xaxis. I plan to export these as .svg and depending on the scaling it just looks awful (they also look bad as .png). The other side of the x-axis looks fine.

Does anyone have an idea as to what could be causing this? I am using Matplotlib 3.4.3 and Python 3.9.7.

(So far I haven’t been able to reproduce this behaviour in a MWE and otherwise it would be a hole load of code and data)

Edit: It seems that my image wasn’t uploaded with the post, trying to fix it…

Image: https://imgur.com/a/aadLbpO

submitted by /u/Thunderflower58
[link] [comments]  Hi everybody, I didn’t find anything on this problem while searching the web. When adding a second x-axis to my plots, the secondary axis seems to lack anti-aliasing or sth (it just looks weirdly bold and pixelated). The secondary axis is added with ax.secondary_xaxis. I plan to export these as .svg and depending on the scaling it just looks awful (they also look bad as .png). The other side of the x-axis looks fine. Does anyone have an idea as to what could be causing this? I am using Matplotlib 3.4.3 and Python 3.9.7. (So far I haven’t been able to reproduce this behaviour in a MWE and otherwise it would be a hole load of code and data) Edit: It seems that my image wasn’t uploaded with the post, trying to fix it… Image: https://imgur.com/a/aadLbpO submitted by /u/Thunderflower58 [link] [comments]

Read more

Is there a way to tell if a package I downloaded connects to the internet when I’m using it? /u/OutRagousGameR Python Education

Is there a way to tell if a package I downloaded connects to the internet when I’m using it? /u/OutRagousGameR Python Education

I’m looking to download a personal, local LLM.

Plus, if I’m going to integrate personal files with an open source LLM (like Llama or Private GPT), I want to make sure that my data/prompts aren’t being delivered back to its developers (like Meta).

I’m new to python, self taught. And I’m using a Mac

submitted by /u/OutRagousGameR
[link] [comments]

​r/learnpython I’m looking to download a personal, local LLM. Plus, if I’m going to integrate personal files with an open source LLM (like Llama or Private GPT), I want to make sure that my data/prompts aren’t being delivered back to its developers (like Meta). I’m new to python, self taught. And I’m using a Mac submitted by /u/OutRagousGameR [link] [comments] 

I’m looking to download a personal, local LLM.

Plus, if I’m going to integrate personal files with an open source LLM (like Llama or Private GPT), I want to make sure that my data/prompts aren’t being delivered back to its developers (like Meta).

I’m new to python, self taught. And I’m using a Mac

submitted by /u/OutRagousGameR
[link] [comments]  I’m looking to download a personal, local LLM. Plus, if I’m going to integrate personal files with an open source LLM (like Llama or Private GPT), I want to make sure that my data/prompts aren’t being delivered back to its developers (like Meta). I’m new to python, self taught. And I’m using a Mac submitted by /u/OutRagousGameR [link] [comments]

Read more