Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
What is the best way of doing integration test with flask?

I am trying to make an integration test using thread, using multiple ports. But it is not working very well. What is the best way of doing it?

def get_server():
Server = Thread(target=main)
Server.daemon = True
return Server

def test_update_blockchain():
sys.argv = ['','--port', '8002','--wallet','1']
ip1 = f'http://localhost:8002'
server1 = get_server()
server1.start()
time.sleep(0.01)

sys.argv = ['','--port', '8003', '--wallet', '2', '--servers', 'localhost:8002']
ip2 = f'http://localhost:8003'
server2 = get_server()
server2.start()
time.sleep(0.01)

requests.get(f'{ip1}/mine')
res = requests.get(f'{ip2}/blockchain')
assert res.status_code == 200
blockchain = res.json()
assert len(blockchain['blocks']) == 1

/r/flask
https://redd.it/8qz382
Is it a good idea to make a text-based story game in Python?

I'm doing this because Python is like the easiest language but I don't know if I should use it. Help?

/r/Python
https://redd.it/8qyhn6
how do you prevent this human error before deploy?

often I need to change some code in order to access a part of my app I wouldn't otherwise be able to reach (e.g. access a payment fail view by hand coding in success is always False). It is super easy to forget to correct such changes before commit or even push to server.

How do you catch these human errors? I guess an option is writing a unit test to explicitly make sure you undo the mods. Seems a bit overkill though.

I find myself wanting to be able to label my change (eg #hack) and then detect for any such labels on deploy to stop deploy. Again, perhaps overkill?


/r/django
https://redd.it/8r1gha
Renaming the main flask file

I have a flask app where the main .py file has a hyphen in the filename, and now that I’m trying to run some shell commands I realize that the hyphen is going to be giving me invalid character syntax errors.

I renamed that file to no longer have the hyphen, and then updated the path in two files in my app/py_cache file which referenced that old file name, but I’m now getting errors when I try to start my server, since it still appears to be looking for the old file name somewhere. I can’t tell where the error is coming from, and I’ve searched through all my app files but I can’t find any other references to the old name.

I’ve tried searching for info about this but somehow to no avail so far... Any ideas what I could be missing here? Or is there a better way to rename it than manually changing the paths in those files?

/r/flask
https://redd.it/8qwaz1
Kyso - Publish Your Jupyter Notebooks as Blog Posts

Hi Guys - the founders of kyso here.

Kyso (https://kyso.io) is a blogging platform for data science. We render your jupyter notebooks, including all code, interactive visualisations and rich markdown, as awesome data blogs.

Upload existing notebooks, import your repos from Github and start brand new Jupyterlab environments in the cloud, all for free.

And then publish and share your blogs with the community!

Have a look here for a few example posts on our platform:

https://kyso.io/jamesle/fifa18

https://kyso.io/vanaurum/algorithmic-portfolio-optimization

https://kyso.io/Don/a-journey-to-the-tip-of-neural-networks

https://kyso.io/waldohiding/twitter

Happy to hear any and all feedback!

/r/IPython
https://redd.it/8r2lsf
Recommend a scipy.stats.chisquare ad hoc test?

Hello again,
My scipy chi square test of independence returned a p-value of 0.000, I have age/gender groups 0-14 Male and 0-14 Female etc up to 95.

Should I apply an ad hoc test to the whole datatset, or should I break up the catergories and do the chi-square rest for each age/gender group? I.e. compare 0-14 M to 0-14F to test for independence?

Thanks

/r/pystats
https://redd.it/8r4rkr
Creating/Updating multiple object instances

I am trying to wrap my head around how to structure a form that will allow me to create/update a variable number object istances.

I currently have a view that dynamically generates budget line items based on a project number in the URL parameter. All budget items live in model (A).

In model (B), I need to allow the user to enter/update a number for each budget line item. All this needs to happen on the same page.

To visualize: https://i.imgur.com/PN58dRD.png

The *Fcst Hrs* column is where the user will enter/update items for model (B). Each line they're updating/creating will be a row in my DB. I just don't know how to structure this in django.

/r/django
https://redd.it/8r4ude
Decided to start learning Python last week, and using Python and Spotify's API, I created a playlist that's automatically updated from BestEverAlbums.com's Top tracks of all time list

Using a throwaway since I cannot change my Spotify username

The playlist is here: https://open.spotify.com/user/1285950058/playlist/0d8k1FfVCrCZUnSXTcAlUE

The playlist is generated from crawling the first 10 pages of the songs on this list: https://www.besteveralbums.com/topratedstats.php?o=track

The playlist is set to update every day, though I don't know how much this list changes over time.

There's some limitations, however:

* If the song isn't on Spotify, there's not much I can do about that.
* If the text of the song doesn't match the name of the song exactly on Spotify, the song won't get added to the playlist. (I'm trying to figure out a way to make the search results more accurate)
* I could not get the crawler to actually add the songs in order, so the order right now is random

Using this method, I was able to accurately add 84 out of the top 100 songs on this list.

I'd love to hear your feedback, and feel free to follow the playlist!

(Sorry if this breaks any rules on the subreddit)

/r/Python
https://redd.it/8r5dku
Kyso – Publish Your Jupyter Notebooks as Blog Posts

Hi Guys - the founders of kyso here.

Kyso (https://kyso.io) is a blogging platform for data science. We render your jupyter notebooks, including all code, interactive visualisations and rich markdown, as awesome data blogs.

Upload existing notebooks, import your repos from Github and start brand new Jupyterlab environments in the cloud, all for free.

And then publish and share your blogs with the community!

Have a look here for a few example posts on our platform:

https://kyso.io/jamesle/fifa18

https://kyso.io/vanaurum/algorithmic-portfolio-optimization

https://kyso.io/Don/a-journey-to-the-tip-of-neural-networks

https://kyso.io/waldohiding/twitter

Happy to hear any and all feedback!

/r/JupyterNotebooks
https://redd.it/8r2ilv
Need help with HTML Scraping and webdriving

Howdy! Relatively new to python so apologies if this is simple stuff.

Im currently writing some code to scrape [this](https://heroesofthestorm.com/en-us/leaderboards/hero/8/americas/?optimizelyId=8603521632&analyticsEnv=prod) page for the data in the table. I have the scraper set up with pandas and able to print a csv or xls and everything, but it seems by the way the html is written the parsing only registers the first 50 rows unless the "load more" button is clicked (at which point, the next 50 rows register in the html).

I thought that I could use selenium to automatically click the button for me, but then I realized the scraper will still just use the base website, not the specific page that I have "clicked" the button to load the rest of the table on.

I can't seem to find anything useful for how I could get the scraper to reference the specific page that the driver opens and does its thing on. However, if theres a way I can do it without the webdriver that would also be useful.

I can provide my code if necessary.

/r/Python
https://redd.it/8r683w
Vue.js and Django

Hello my fellow Djangonauts!

I'm going to be starting a new job in a couple weeks using Vue.js with Django, and I was curious if anyone had any solid Vue.js learning materials they could point me to.

The company is going to be transitioning to Vue.js right when I get there, and I was brought in to assist with the architectural decisions going forward. So my main focus is to understand Vue.js and as it relates to the architecture and Django.

Anything and everything is appreciated!

/r/django
https://redd.it/8r6x33
Confused about what's meant by confiugrations

I'm going over the mega tutorial and I'm a bit confused why the whole deal with configurations is, as the tutorial just kind of states it there without much explanation.

 

firstly, the author states that configurations are means of creativity in my application


"But for any applications except the simplest ones, you are going to find that Flask (and possibly also the Flask extensions that you use) offer some amount of freedom in how to do things, and you need to make some decisions, which you pass to the framework as a list of configuration variables."




 


But what's exactly meant by configurations? And how does it tie in with my freedome to write my application how I want to?

 

Then in order to specify my configuration options these blocks of test were given

import os

class Config(object):
SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'

and

app = Flask(__name__)
app.config.from_object(Config)


But what's being configured here? An encryption key? And how is that tied to the overall definition of configurations? Also what is `app.config.from_object(Config)` doing?

/r/flask
https://redd.it/8r5g0r
Deploying and maintaining a Django project with PyCharm Pro ?

I know there are more appropriate ways of deploying and maintaining a Django project, than using PyCharm Pro.

Although, I would like to hear from those who have tried it or use it this way what were their experiences.

It's one of the main reasons that have kept me back regarding Django.

/r/django
https://redd.it/8r7tbd
Data Sets and Challenge Statements Released for this year's Hack for the Sea

The [Hack for the Sea](https://hackforthesea.tech) Crew is proud to present this year's challenge statements and data sets.

They are, as follows:

* [How does a changing coastal watershed impact coastal waters?](https://hackforthesea.tech/GLO/challenge/1)
* [Can you predict where and when cod spawning will occur?](https://hackforthesea.tech/GLO/challenge/2)
* [Can an individual whale be identified based on its blowhole?](https://hackforthesea.tech/GLO/challenge/3)
* [Can you design a mooring that's both eelgrass and user-friendly?](https://hackforthesea.tech/GLO/challenge/4)

The event is all ages and open to anybody who is ready and willing to provide their skills to help the oceans. Also, while the summit will be held in person, the community is open and involved year round. Join us!

/r/pystats
https://redd.it/8r4901
Django FormSets passing different kwarg to each form

Hello.

I have been using forms just fine, but have never used a formset before and am having a lot of difficulty figuring out how to pass kwargs to each form in the set.

I have a basic form like this:

class QuestionForm(forms.Form):
choices = \[(1, 'very poor'), (2, 'poor'), (3, 'fair'),
(4, 'good'), (5, 'very good')\]

score = forms.ChoiceField(widget=forms.RadioSelect, required=True)

What I want is for each form in the set to have access to a question\_id and question\_description.

I was reading through the documentation, but the documentation about passing custom kwargs to each form is not very clear to me.

If anyone could help me understand how to achieve this, I would very grateful.

/r/django
https://redd.it/8r7c74