Re: Regarding Regex timeout behavior to minimize CPU consumption
Hi, Timeout: no idea. But check out re.compile and re.iterfind as they might speed things up. I often compile a regex once upon import, then use it in functions On 27 Nov 2020 13:33, Shahique Khan wrote: Hi Team, I have noticed if our regex sometimes does not give a result and on that time regex took more time in returning response (empty response). My Question is can we set a timeout parameter (in seconds/millisecond) with re.find or anywhere in code to avoid CPU consumption if regex takes more time in execution. Below is the example, which take more time in execution: (in this case can we set timeout to kill the execution to avoid CPU consumption) regex = r'data-stid="section-room-list"[\s\S]*?>\s*([\s\S]*?)\s*' \ r'(?:class\s*=\s*"\s*sticky-book-now\s*"|\s*|id\s*=\s*"Location")' rooms_blocks_to_be_replace = re.findall(regex, html_template) Please help me, I will be very thankful for this. Thanks, -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Bot
Try Selenium (preferred) or Mechanize. I recently used Selenium with Chrome for automated unittests of a web app, including a login screen. You could fire up the selenium script in a cron job at the desired time. On 1 Dec 2020 09:53, Álvaro d'Ors wrote: Hi guys, I'm new here, can anyone help me built a bot than can input data in a website? This is not for spam purposes, I just need to reserve a place in the library at the university but they are completed in a matter of minutes and I can't waste time "camping" the website. Thank you Nestares D. Álvaro -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: How do I get datetime to stop showing seconds?
On 16 Oct 2020 12:50, Eryk Sun wrote: On 10/16/20, Steve wrote: > -Original Message- > From: Python-list On > Behalf Of Frank Millman > Sent: Friday, October 16, 2020 4:34 AM > To: python-list@python.org > Subject: Re: How do I get datetime to stop showing seconds? > > On 2020-10-16 9:42 AM, Steve wrote: >> d2 = datetime.datetime.now() #Time Right now >> I was using datetime.now().isoformat('T', 'seconds') Not 100% sure, but the strings seemed to be 2hrs off. Could it be that this Linux server was using the wrong time zone? -- https://mail.python.org/mailman/listinfo/python-list
Re: Hot reload Flask app?
On 1 Oct 2020 17:58, Roland Müller via Python-list wrote: On 2020-10-01 16:33, sjeik_ap...@hotmail.com wrote: > Hi, > I would like to create a "/reload" view in my Flask app, so I could easily > and safely reload it when code, templates etc change. Similar to what > happens when running the app with the debug server. I am using Nginx and > Gevent on a recent Ubuntu system with Python 3.6. > My strategy would be to gracefully stop Gevent [1], then do > os.kill(os.getpid(), signal.SIGHUP). I have not yet tried this (not > working today!). Just wondering if there are best practices. > Thanks! > Albert-Jan > [1] > http://www.gevent.org/api/gevent.baseserver.html#gevent.baseserver.BaseServer.stop Running flask app.run(debug=True) will make the Flask server watching the filesystem for source code changes and re-deploy your app. https://pythonhosted.org/Flask-Debug/ ==》 Hi, Thanks. I was aware of running it in debug mode, but I was looking for domething to use in production. I checked how werkzeug does it, see line 160: https://github.com/pallets/werkzeug/blob/master/src/werkzeug/_reloader.py I'll study this in more detail tomorrow. Best wishes, Albert-Jan -- https://mail.python.org/mailman/listinfo/python-list
Hot reload Flask app?
Hi, I would like to create a "/reload" view in my Flask app, so I could easily and safely reload it when code, templates etc change. Similar to what happens when running the app with the debug server. I am using Nginx and Gevent on a recent Ubuntu system with Python 3.6. My strategy would be to gracefully stop Gevent [1], then do os.kill(os.getpid(), signal.SIGHUP). I have not yet tried this (not working today!). Just wondering if there are best practices. Thanks! Albert-Jan [1] http://www.gevent.org/api/gevent.baseserver.html#gevent.baseserver.BaseServer.stop -- https://mail.python.org/mailman/listinfo/python-list
Re: i am want to read data from the csv that i wrote using python csv module but apart from filed names and row count i am unable to read rest of the data
On 15 Apr 2020 10:28, Peter Otten <__pete...@web.de> wrote: sjeik_ap...@hotmail.com wrote: > On 12 Apr 2020 12:30, Peter Otten <__pete...@web.de> wrote: > > Rahul Gupta wrote: > > >for line in enumerate(csv_reader): > >print(line[csv_reader.fieldnames[1]]) > > enumerate() generates (index, line) tuples that you need to unpack: > > for index, line in enumerate(csv_reader): > print(line[csv_reader.fieldnames[1]]) > > ==》 Shouldn't that be, e.g: > print( line[csv_reader.fieldnames[1].index()] ) No. Remember that the OP used a DictReader. If you want to clean up the original code you can use a csv.reader csv_reader = csv.reader(csv_file) fieldnames = next(csv_reader) for row in csv_reader: print(row[1]) but my assumption was that > print(line[csv_reader.fieldnames[1]]) wasn't the final code, only something to get things working. > Or maybe: > cols = csv_reader.fieldnames > print( [[val for val, col in zip(record, cols) if col in ['somecol']] > for record in csv_reader]) > ? This is ugly and complex. It can be simplified to num_rows = sum(1 for _ in csv_reader) print([["somecol"]] * num_rows) Why would you want to this? ===》 I thought the OP wanted to take a subset of the columns in his data. In my example I intended to select one column, but with code that cpuld easily be extended to a selection of multiple columns. Call it "pruning" of the lists of lists -- https://mail.python.org/mailman/listinfo/python-list
Re: i am want to read data from the csv that i wrote using python csv module but apart from filed names and row count i am unable to read rest of the data
On 12 Apr 2020 12:30, Peter Otten <__pete...@web.de> wrote: Rahul Gupta wrote: > for line in enumerate(csv_reader): > print(line[csv_reader.fieldnames[1]]) enumerate() generates (index, line) tuples that you need to unpack: for index, line in enumerate(csv_reader): print(line[csv_reader.fieldnames[1]]) ==》 Shouldn't that be, e.g: print( line[csv_reader.fieldnames[1].index()] ) Or maybe: cols = csv_reader.fieldnames print( [[val for val, col in zip(record, cols) if col in ['somecol']] for record in csv_reader]) ? -- https://mail.python.org/mailman/listinfo/python-list