Nobody Reads This

Archimonde: You are very brave to stand against me, little human.

And I have no Illusions Otherwise.
  • Home
  • Images
  • Videos
  • About JamesR

My Python needs a Shaft

James Reynolds | August 28, 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.

Comments
No Comments »
Categories
General Junk
Tags
Badly, Converter, Python, Terrible Coding, XML to CSV
Comments rss Comments rss
Trackback Trackback

Ups, You did it again

James Reynolds | August 28, 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.

Comments
No Comments »
Categories
General Junk
Tags
Art Manga Links, Crabcakes, Cunt Features, Jewfro Extraganza, Leslie, Mark is a Jew, Resuri, UPS
Comments rss Comments rss
Trackback Trackback

Brief Post

James Reynolds | August 26, 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!

Comments
1 Comment »
Categories
General Junk
Comments rss Comments rss
Trackback Trackback

Google, worse than AT&T?

James Reynolds | August 18, 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.

Comments
No Comments »
Categories
General Junk
Tags
AT&T, AT&T are a bunch of ass clowns, Google, Spying
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Tweet

  • RT: @happymrlocust Wow, O2 goes to bat for it's customers over what is essentially extortion. http://bit.ly/a8mkrh o_O' Wow, good to know! 3 hours ago

Blogroll

  • Beagle2’s Brain
  • Laputan Machine
  • Lost Caykes
  • Rasberry lOlly’s Blog
  • Resuri’s Blog
  • Twitter (JamesR87)
  • WS@Vlogging
  • Yet Another Blog

Misc

  • Bunny
  • Ctrl+Alt+Delete
  • Cyanide & Happiness
  • Dinosaur Comics
  • Penny Arcade
  • Questionable Content
  • VGCats
  • XboxElite.co.uk
  • XKCD

WoW Blogs

  • Gnomeaggedon
  • MMO Champ
  • WoW.com

Gamercard

Statistics

  • Total Stats
    • 353 Posts
    • 466 Comments

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Cats

Arcs

Calendar

August 2008
M T W T F S S
« Jul   Sep »
 123
45678910
11121314151617
18192021222324
25262728293031

Akismet

9,614 spam comments
blocked by
Akismet
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox