![]() |
|
** Python Support Thread **
I'm getting started with Python the old fashioned way; trying to do something for work so I look better than the rest of the schlubs I work with. I'll update this with what I'm looking to do and what current problems I'm researching. Feel free to add your own questions or answers.
We are in the process of rolling our own tools to get information about the servers we support through rest calls instead of running scripts on the servers themselves. What I'm trying to do is generate a list of users who have been offline for a day. There are rest calls that return all users on a server with their registration status. I'm using that to generate a list of registered users who I then make a rest call to see the last time they called into the server. If they haven't called in within a day they are "offline," and if they haven't called in within two years they have never been online. The first pass into date math was almost successful and is what I'm going to be digging into today. This works as long as the date is past the first of the month: today = datetime.datetime.today() #TODO: Fix for first day of month start_date = today.replace(day=today.day-1).strftime("%Y-%m-%dT%H:%M:%S.000") Any tips or tricks for dealing with date strings would be appreciated. |
Re: Python Support Thread
I'm not entirely sure what you're trying to do - but check out timedelta. It'll make life way easier when doing checks of time ranges (like within the past day).
|
Re: Python Support Thread
The rest calls use start dates that I calculate and timedelta is what I found and got working. We have equipment in people's homes that take readings and send them up to our servers. The rest calls let me see the latest reading from a time period and to see if they have ever got a read I need to walk back a month at a time and make another call.
I think it's all working, now I'm getting it to email the results so I can automate it. |
Re: Python Support Thread
Oh nice. This is definitely something that can be written pretty concisely in Python.
|
Re: Python Support Thread
http://imgs.xkcd.com/comics/python.png
I wrote 20 short programs in Python yesterday. It was wonderful. Perl, I'm leaving you. |
Re: Python Support Thread
wow new forum, great stuff!!
just curious but I figure I might as well ask before I invest what little time I have... Is it possible to write a Windows based HUD with Python? Any tips on tools, frameworks, libraries? |
Re: Python Support Thread
Certainly possible, I haven't done any Pythong GUI stuff outside Pygame but it can handle SQL pretty well (assuming the underlying database is SQL based) and PyQT or something looks good for gui stuff as well.
Also, we need the title to be bold and with stars like the other ones :D |
Re: Python Support Thread
Ok, I just realized that FPDB is written in Python so obv it's possible.
Maybe I'll just take a look at FPDB instead :D |
Re: Python Support Thread
Quote:
|
Re: ** Python Support Thread **
A quickie to move up to a given number of files from one directory to another, we had to change an inbound directory that was getting killed and limit the number of files that hit it at once. Be kind, I'm new at this..., and I know I need to clean up the import...
Code:
#!/usr/bin/env python |
Re: ** Python Support Thread **
Checkout optparse (http://docs.python.org/library/optparse.html), that'll clean that up a lot.
|
Re: ** Python Support Thread **
+1 for optparse.
Other than that there isn't much.
|
Re: ** Python Support Thread **
I do need to look at optparse, it's been lower priority because I needed to learn everything else... :)
I probably tried =! or <> the first time and it didn't work and fell back on not(). So I should be able to say if x==1 or y==2: I think that is where I tend to over use parenthesis. I'm still note entirely clear on when things can be converted to strings and when they can't. Doing it on a separate line then making the function call probably grew out of fixing two things on an error and trying again instead of fixing one thing... Thanks for the input! |
Re: ** Python Support Thread **
Don't forget you can use the C style (is it actually called that?) string syntax.
So: outLine = "Number " + str(count) could be: outLine = "Number %d" % count It's probably 'good' (meaning it doesn't really matter) to always use the string syntax. I've also had a hell of a time becoming 100% sure on when to convert or not. I've had a few hard-to-debug bugs where I had a number as a string and forgot to convert it to an int before a comparison. |
Re: ** Python Support Thread **
Quote:
Quote:
Quote:
Quote:
|
Re: ** Python Support Thread **
Quote:
At least in Python3 all text is unicode, hurray (you won't appreciate this untill you al of a suddne have a Japanses/Chinese customer) |
Re: ** Python Support Thread **
I use modified Python scripts to scrape/process HTML DOM objects. It is awesome for that. Developing full web-based apps... eh. I don't like it for that. But yeah I prefer it over Perl for regex and purely scripting-based stuff.
|
Re: ** Python Support Thread **
Quote:
I'm still not sold on building large applications in it - but it's growing on me. |
Re: ** Python Support Thread **
All I can say is that Python is amazing for building large applications and you can get stuff done extremly fast (and clean imo). I used to work on a project that would qualify as pretty big.
It's always fun to go to a customer, discuss and hear something along the lines of "well your software seems perfect except it can't do X yet", make a phone call, go to lunch with them and when you come back to their office said feature is commited with tests. Rapid development (and having great developers) is a very strong tool for pitching a product fwiw. |
Re: ** Python Support Thread **
What do you qualify as pretty big? In terms of team size and code base.
I definitely have an open mind when it comes to building large applications in Python. I'm skeptical though that it wouldn't turn into a nightmare with a team of more than 4 or 5 people and even worse it feels like a language where one bad developer can really screw over a lot of people. |
Re: ** Python Support Thread **
Quote:
Code base is >5 million lines of code iirc (not that LOC is a meaningfull measure anyways) Quote:
Add a strict separation of the stable branch from the current devel one and customer specific customizations and it's really hard to screw anything up :) I'll say though that I was kind of sceptical that Python could be used for anything big before working on this system but I was won over pretty quickly. From a business POV you also have customers every now and then who will aks you "wtf is this Python, business software is supposed to be written in insert language, usually JAVA" so I suppose JAVA does have a marketing edge of sorts. tl;dr: just try it :) |
Re: ** Python Support Thread **
Quote:
outline = "Number {0}".format(count) which is meant to be more powerful and work in all recent versions of Python. But I could be totally wrong, I don't have Python 3. |
Re: ** Python Support Thread **
str.format()
Quote:
|
Re: ** Python Support Thread **
Ah, interesting. Good to know. Looks like its available starting in 2.6 (which is what I use).
|
Re: ** Python Support Thread **
Starting to pick up programming again; my only experience was in QBASIC as a pre-teen back in the 90s. Decided on a whim yesterday to try to learn Python.
Anyway, Is there an easy (I'll settle for hard) way to display a variable using tkinter and have the display update as the variable changes? I started off using a label, but it didn't update dynamically, and the solutions I've found online so far seem to go about solving it in a very roundabout way. TIA for any help! |
| All times are GMT -4. The time now is 06:21 AM. |
|
Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright © 2008-2020, Two Plus Two Interactive