librelist archives

« back to archive

Newbie Flask: How to make a continuous loop using Python 3.4.1 + Flask

Newbie Flask: How to make a continuous loop using Python 3.4.1 + Flask

From:
Juan Christian
Date:
2014-09-27 @ 17:05
I have this temporary code that I made with Python 3.4.1:
http://pastebin.com/aauRQJX1

Running via terminal works, as expected. But now I want to make a web app
using Flask, my main concern is that the function 'fetch_forum()' needs to
be continuously called, in the code I use a 'while True' +
'time.sleep(int(interval))' to regulate the "speed", to achieve it, how can
I set this function to works like this in a web environment?

I read the doc, did the "quickstart" tutorial but I didn't found any info
about this.

Re: [flask] Newbie Flask: How to make a continuous loop using Python 3.4.1 + Flask

From:
Christian Barra
Date:
2014-09-27 @ 18:34
Where's your flask app ?

2014-09-27 19:05 GMT+02:00 Juan Christian <juan0christian@gmail.com>:
> I have this temporary code that I made with Python 3.4.1:
> http://pastebin.com/aauRQJX1
>
> Running via terminal works, as expected. But now I want to make a web app
> using Flask, my main concern is that the function 'fetch_forum()' needs to
> be continuously called, in the code I use a 'while True' +
> 'time.sleep(int(interval))' to regulate the "speed", to achieve it, how can
> I set this function to works like this in a web environment?
>
> I read the doc, did the "quickstart" tutorial but I didn't found any info
> about this.



-- 

Best,
Christian

Re: [flask] Newbie Flask: How to make a continuous loop using Python 3.4.1 + Flask

From:
Matthias Urlichs
Date:
2014-09-27 @ 18:26
Hi,

Juan Christian:
> Running via terminal works, as expected. But now I want to make a web app
> using Flask, my main concern is that the function 'fetch_forum()' needs to
> be continuously called, in the code I use a 'while True' +
> 'time.sleep(int(interval))' to regulate the "speed", to achieve it, how can
> I set this function to works like this in a web environment?
> 
You need a way to feed data to your web client.
I'd investigate flask-socketio. (Its docs warn that gevent doesn't yet work
with Py3, which is outdated.)

You'll have to write some Javascript for the client, unfortunately. :-/

(Is there a py2js project that people actually use in production code?)

-- 
-- Matthias Urlichs

Re: [flask] Newbie Flask: How to make a continuous loop using Python 3.4.1 + Flask

From:
Juan Christian
Date:
2014-09-27 @ 19:21
I'm using python 3.4.1, in the site it says that it only supports python
2.x. =/

On Sat, Sep 27, 2014 at 3:26 PM, Matthias Urlichs <matthias@urlichs.de>
wrote:

> Hi,
>
> Juan Christian:
> > Running via terminal works, as expected. But now I want to make a web app
> > using Flask, my main concern is that the function 'fetch_forum()' needs
> to
> > be continuously called, in the code I use a 'while True' +
> > 'time.sleep(int(interval))' to regulate the "speed", to achieve it, how
> can
> > I set this function to works like this in a web environment?
> >
> You need a way to feed data to your web client.
> I'd investigate flask-socketio. (Its docs warn that gevent doesn't yet work
> with Py3, which is outdated.)
>
> You'll have to write some Javascript for the client, unfortunately. :-/
>
> (Is there a py2js project that people actually use in production code?)
>
> --
> -- Matthias Urlichs
>

Re: [flask] Newbie Flask: How to make a continuous loop using Python 3.4.1 + Flask

From:
Matthias Urlichs
Date:
2014-09-27 @ 21:25
Hi,

Juan Christian:
> I'm using python 3.4.1, in the site it says that it only supports python
> 2.x. =/
> 
As I said, this is likely to be outdated. gevent works with Py3.

Fixing any remaining problems is likely to be rather easy;
in any case I'm going to need socketio myself Real Soon Now,
so if you do run into any problems don't hesitate to holler for help.

--
-- Matthias Urlichs

Re: [flask] Newbie Flask: How to make a continuous loop using Python 3.4.1 + Flask

From:
Juan Christian
Date:
2014-09-28 @ 02:06
On Sat, Sep 27, 2014 at 6:25 PM, Matthias Urlichs <matthias@urlichs.de>
wrote:

> Hi,
>
> Juan Christian:
> > I'm using python 3.4.1, in the site it says that it only supports python
> > 2.x. =/
> >
> As I said, this is likely to be outdated. gevent works with Py3.
>
> Fixing any remaining problems is likely to be rather easy;
> in any case I'm going to need socketio myself Real Soon Now,
> so if you do run into any problems don't hesitate to holler for help.
>


I was playing with MongoDB before starting all this loop thing, and I found
a little "issue".

I have the following code: http://pastebin.com/uZhiX7cM

It's working, but I've a little problem. I'd like to use the modified steam
API from PyPI (ln. 21), rather than calling the original steam API (ln. 22
- 23). The problem is that MongoDB doesn't accept if I try to do the
db.users.insert with a "SteamUser" object (ln. 21), it's because the object
returned from this API isn't an iterable.

What do I do? I do need to save this in a DB, maybe I should choose another
one?

Using the modified API is essential as it's half of the job done and it's a
great and very well made API interface.

Re: [flask] Newbie Flask: How to make a continuous loop using Python 3.4.1 + Flask

From:
Matthias Urlichs
Date:
2014-09-29 @ 16:06
Hi,

Juan Christian:
> It's working, but I've a little problem. I'd like to use the modified steam
> API from PyPI (ln. 21), rather than calling the original steam API (ln. 22
> - 23). The problem is that MongoDB doesn't accept if I try to do the
> db.users.insert with a "SteamUser" object (ln. 21), it's because the object
> returned from this API isn't an iterable.
> 
It needs to be a dictionary (which is what the JSON decodes to), not an
object (or whatever the steam code returns).

This is no longer in any way flask-related; how to put an object's
attributes into a dict is left as an exercise to the reader.
(Besides, I don't know your data scheme.)

-- 
-- Matthias Urlichs

Re: Newbie Flask: How to make a continuous loop using Python 3.4.1 + Flask

From:
Juan Christian
Date:
2014-09-30 @ 13:36
Issue resolved, using a different approach. Yes, my fault, not related to
Flask. Thanks. :)

On Monday, September 29, 2014, Matthias Urlichs <matthias@urlichs.de> wrote:

> Hi,
>
> Juan Christian:
> > It's working, but I've a little problem. I'd like to use the modified
> steam
> > API from PyPI (ln. 21), rather than calling the original steam API (ln.
> 22
> > - 23). The problem is that MongoDB doesn't accept if I try to do the
> > db.users.insert with a "SteamUser" object (ln. 21), it's because the
> object
> > returned from this API isn't an iterable.
> >
> It needs to be a dictionary (which is what the JSON decodes to), not an
> object (or whatever the steam code returns).
>
> This is no longer in any way flask-related; how to put an object's
> attributes into a dict is left as an exercise to the reader.
> (Besides, I don't know your data scheme.)
>
> --
> -- Matthias Urlichs
>