My Python needs a Shaft

28 08 2008

You know you’re massively out of practice when it takes 63 lines of Python just to filter an XML file and convert what you get into a CSV file.

I think if I really tried I could get it down to 15-20 well formed lines … I start with something like standard XML trees and finish with:

1,Back_Only,Use_Job_Setting,Tabloid,
2,Different,Use_Job_Setting,Tabloid,
3,Back_Only,Use_Job_Setting,Statement,
4,Different,Use_Job_Setting,Statement,
5,Back_Only,Use_Job_Setting,Executive,
6,Different,Use_Job_Setting,Executive,
7,Back_Only,Use_Job_Setting,8_5_x_13,
8,Different,Use_Job_Setting,8_5_x_13,

The code is thus:

## Fireeye XML Test Plan to CSV converter.
## Scripted by James Reynolds

def main():
print “Filename (*.xml): “
fileName = raw_input()
fileHold = open(fileName, “rb”)
fileContent = fileHold.readlines()
fileContent = relist(fileContent)
print “Read and Relisted”
writeTo = open(fileName.replace(”.xml”,”.csv”), ‘w’)
print “Writing to ” + fileName.replace(”.xml”,”.csv”)
for i in fileContent:
string = listToCSV(i)
string = remXML(string)
writeTo.write(string)
print “Done.”

## Takes XML doc and filters out what we need returning list of tests
def relist(fileContent):
master = []
sub = []
adder = False
for element in fileContent:
if (element.find(”Testcase TCNo”) >= 0):
adder = True
elif (element.find(”") >= 0):
adder = False
sub.append(element)
master.append(sub)
sub = []
if (adder == True):
sub.append(element)
return master

## Takes list and reformats to CSV
def listToCSV(varList):
csvString = “”
for element in varList:
if (csvString == “”):
element = element.replace(”\r\n”, “”)
element = element.strip()
csvString = csvString + element
else:
element = element.replace(”\r\n”, “,”)
element = element.strip()
csvString = csvString + element
csvString = csvString + “\r\n”
return csvString

## Removes XML tags
def remXML(XMLstring):
delete = False
newString = “”
for i in XMLstring:
if (i == “<”):
delete = True
if (i == “>”):
delete = False
if (delete == False and i != “>”):
newString = newString + i
return newString.replace(”,,”,”,”)
main()

You can probably see the though process … “I need it to do this. Oh, it won’t? Ok … This. That’s not quite right … What if I had this? Nearly there … And done. Next …”

Clearly not the best way to program … Knowing me I’ll sit down and rewrite it to be a lot better some time soon but … Meh.

Check out todaysbigfail.com, it’s run by another IP here.

Regards,
JamesR.

Wonders if his title is an obvious enough reference.





Ups, You did it again

28 08 2008
UPS, guranteed to piss off the working class

UPS, guranteed to piss off the working class

I find it quite funny that UPS tries to deliver a package three times in one working week – I ask you, do they expect us to randomly be in one midday but not the next? I’m beginning to wonder exactly where in the scheme of good business sense delivery companies sit …

How many millions (tens or hundreds?) of people around the world work 9-5~ and can’t be in for the mail? Where is the option to have it delivered on a Saturday or a Sunday? It’s that bloody simple! Or perhaps have it delivered earlier in the morning like 5-7 but that doesn’t help some people…

Consider that if we opt to pick it up, they don’t even man the depots on weekends! Jesus tap dancing Mother Theresa’s Ghost Puppy! Who came up with that fucking business plan?

It’s a good thing the company I’m working for are decent human beings and let you deliver to the office …

… Le sigh. Anyway, you might have noticed I have been posting less and this is primarily to do with being in training or not at a PC for the last week and a bit but if I’m honest I generally don’t want to write in the precious little time I have to myself between chores, work and sleep. I am sure this will return to normal once we have a net connection and I pick up my new PC at the end of this week …

In the mean time however you can all do me a favour and head over to Resuri’s (Leslie’s) blog and comment, we were all new to blogging one time or another and it’s always good to have some encouragement at the start. I’d recommend Mark’s blog, but I think she’s already beating him on Posts per week :P

Regards,
James
R.
Systems Software, Hardware Integration.

Quietly proud of the article title.





Brief Post

26 08 2008

Can’t let the Missus outpost me ;)

http://www.comet.co.uk/shopcomet/product/447900/HP-KQ403AA

Picking it, or something close, up some time this week.

Will hopefully do a proper post soon.

Regards,
JamesR.

Rawrlarlarlalglalglaglalarlarllbllgalglarlalglalrlalr!





Google, worse than AT&T?

18 08 2008

Three days ago Wired posted a story entitled “Google Privacy Practices Worse Than ISP Snooping, AT&T Charges“. This is coming off of the news that AT&T was found to be conspiring with the NSA to spy on people’s internet activities and the argument put forward by AT&T is that Google is far guiltier of spying than anyone else.

Amongst other ridiculous things, they say:

If anything the largely invisible practices of ad-networks raise even greater privacy concerns than do the behavioral advertising techniques that ISPs could employ, such as deep-packet-inspection

They might have had a point if it weren’t for the fact that we as users of the internet are wholly in charge of what our browser sees and does allowing us to disable tracking cookies and web scripts altogether. Even with an opt-out option, what is to stop agencies subpoenaing the ISPs and forcing them to track or disclose the information available to them.

Ultimately I think we have no reason to distrust Google - Their services are entirely free and their tracking services can be disabled and any histories gathered can be deleted easily via their site. I genuinely believe Google uses the data they gather to provide us with a better experience - Whereas even AT&Ts legitimate reasoning is to help them make money through advertising.

I appreciate Google does this, but then they also provide the best search engine which quite frankly did more to help the internet than all the backbone cables run by the telecom companies.

I honestly find AT&T’s accusations hillarious! They were caught with their hand in the cookie jar, then the NSA scandal was effectively like having their genitals in the cookie jar … Then they turned around and pointed at Google who have a history of filling the cookie jar and accused them of being worse.

It’s retarded AT&T and I hope that not only this class action law suit really hurts but that Google’s retort hurts.

Regards,
JamesR.

Have my own work email and log in now … Huzzah!

News Time! I will be coming down to Gosport Thursday and will be getting into town shortly after mid day. I will be attending the quiz at the Railway and meeting up for something to eat at around 3 or 4.





A Step in the right direction

15 08 2008

So I read just now in a BBC article that at some point an American court ruled that using licenses like CC commons and presumably the GNU by extension to release open source software gives you no rights to copyright infringement when someone then takes your work and uses or alters it in a way your license would not allow.

The decision has of course been overturned by the US Federal Appeals court, but one must consider how exactly the first decision was originally passed. The first court deemed that if you release materials on to the net for free - then there can be no copyright theft.

To make that decision the judge has to basically say that there is no value in being the person who created the software but only in the monetary gains that would reward you with. Would this same judge deem that copying off of someone’s test isn’t cheating if they weren’t covering their answers up?

Perhaps the most shocking thing about this is that the person accused of copyright theft took open source software (with the standard - credit me, update me and tell others where to find the original license) which was then taken, modified and sold on.

The key here is the fact that someone took another persons work broke the lisensing agreement and distributed it for profit - that isn’t just one copyright theft, that’s effectively software piracy.

I’m sure you’re all aware of how media distributors try to get people - By accusing them not of having pirated software (as the penalties are fairly marginal and it’s hard to make a good charge stick) but distributing pirated software which is a far worse crime.

Most open source licenses ask a few things in return for you using their materials:

  • You credit the original author
  • You keep the same license
  • You don’t sell it on

It’s simple, the CC license puts it nicely with “Share and Share alike” because it’s only with this thinking that the arts and sciences can share information without the worry that their good deed will be stolen and marketed by someone else.

In the software world I can think of nothing worse than taking someone’s code that they through good intentions have released to you and selling it on. If you do it, you’re a Judas.

Rant complete.

We (I) have decided that i’m going to let another team join us in our next GTA shoot, there is one guy who has sent us some suggestions via YouTube and I will probably get back to him and tell him to bring a friend.

If you have a better suggestion, i’m all ears.

Regards,
JamesR.

So we bought a Belkin router to be stop gap between getting one from Virgin … And nobody told me that Belkin Wireless G Routers don’t work with Virgin Media Cable modems.

Fuck. Going back into Comet will be a laugh :P





Latham-IT & Photo Updates

14 08 2008

Just popping by really to talk to you about two things and the first is a job opportunity:

I found out recently that a long time friend of mine Sven (creator of Blogwise, amongst other things) has created an IT company and will soon be looking to recruit undergraduate web developers for PHP and MySql work.

The positions will likely be based out of Fratton (Portsmouth) and will include some training. If you think you fit the bill then why not swing by Latham IT and leave them a CV.

Otherwise, here are the photos … They’re nothing special just pictures of my room actually tidy! And a neat collection of bottles.

Still looking for someone with even basic experience of Firefox extensions to talk me through a few things.

Regards,
JamesR.

Currently learning XML and Javascript … Can’t believe I left it this long.