Omniture - python: keyError with authentication - python

I have been trying to use the omniture module to retrieve data from omniture but I am stuck at the very first step.
I followed the instructions on the readme but when I try to authenticate I receive the following traceback:
enter image description here
any little help will be much appreciated !
Thanks a lot,
Bastien

There's no report_suites key in the dictionary. Don't know what are you trying to find, but the best for you would be either print whole dictionary, or more efficient - print only keys and choose the one you want.
If you don't know what key do you want, printing the whole dictionary may be more useful as the values alone would be useless for you without a way to access them.
Also I think you didn't pass enough arguments to the function, because it seems that the function is missing something, therefore can't return what you need.

Related

simple salesforce update on custom field

Is it possible to update an account on salesforce using an external custom field?
I've tried sf.Account.Update("Custom_Field__c:{}.format(field), data) and I cannot seem to get it to work.
I know this is really late, but in case somebody else stumbles on this:
The answer is yes, however your code is formatted incorrectly.
The update method that you're asking about is actually lower-case, it typically takes two arguments to evaluate correctly, a valid SF Id as a string, and the data you want to update with as a dictionary. So to fix what's going on in your question it would look like:
sf.Account.update("15characterIdoftheAccount", {"Custom_Field__c:{}.format(thevalueyouwanttoshowupinSF)})

Python, Returning object class names by a function

I'm new to Python and this is my first question here. Hope any of you guys will be able to help me out.
I'm trying to call values inside an object from an external program. The object that I'm trying to access is given in a class (as i uderstand it), and the name of the class may change according to X, see below:
External programs object and class information
I want to be able to call information from Phase_6 in this case, however it could be Phase_12 in another case. I was considering making a function where i could have the _'Number' as an input. But I can't seem to find any information of how to do such.
I was thinking of something like using +str(X), as I do when plotting. But as it is probably not a string, it doesn't work out.
My proposed code
Ive read that bpy in Blender may be able to replace the name of the class that i want to return, however I'm not sure if it'll work, and I dont want to switch editor :)
Hope you guys can help me out,
Joachim
Found the answer, one could use getattr.
x = 6
result = getattr(g_o, 'phase_'+str(x)).Info.SumMsf.value
Thanks anyway - And I'll work on the pictures
Joachim

Feedparser.parse etag and modified params

import feedparser
d = feedparser.parse('http://rss.cnn.com/rss/edition.rss', etag=d.etag)
I am new to Python and can't get my head around the parameter etag=d.etag
I Don't understand the data type. It's important to me because I am trying to make this parameter as a string dynamically. Does not work. I printed type(d.etag), result is Unicode. So I tried to the Unicode func to form my string. Still no luck. Sorry, I realise this is so basic, I just can't get it. I know, to get the etag working is easy to achieve if you follow the examples from the feedparser site, where you do your first call without a param, then each subsequent call use the etag=d.etag. I am mainly learning on my iPad and am using Pythonista, so I am running my program over and over. I also know I could write it out to a file, and parse the file instead, but I really want to understand why I can't dynamically create this param. I am sure I will hit the same problem with another module sooner or later.

How to add a track to an iTunes playlist using Python and Scripting Bridge

I learned how to create a playlist in a previous question, but now I can't figure out how to add tracks to it. Right now I have:
tracks.sort(key=lambda tup: tup[0])
i = 0
for trackList in generatePlaylists(tracks,10):
i += 1
playlistname = str(i)
p = {'name': playlistname}
playlist = iTunes.classForScriptingClass_("playlist").alloc().initWithProperties_(p)
iTunes.sources()[0].playlists().insertObject_atIndex_(playlist, 0)
# Find the playlist I just made
for playlist in iTunes.sources()[0].playlists():
if playlist.name() == playlistname:
newPlaylist = playlist
# Add the tracks to it
for track in trackList:
print track[1].name()
iTunes.add_to_(track[1],newPlaylist)
My tracks are in a list of tuples tracks, where the first element of the tuple is a score and the second is the actual track object. generatePlaylists is an iterator which splits all library tracks into 10 lists.
The above code runs without error, but in iTunes the playlists are empty.
First, here's the short answer:
track.duplicateTo_(newPlaylist)
The problem is that iTunes.add_to_ sends the add command, which takes a file (alias) and imports it into a playlist; you want to send the duplicate command, which takes any object and makes another copy of the object. You don't have a file, you have a track. (You could get a file via track.location(), but you don't want to re-import the file, just copy the track over.)
Also, in this case, you need to call the method on the track, rather than calling it on the app and passing it the track.
The first half of this is hard to explain without a solid understanding of the iTunes object model (and the AE model underneath it). But you don't really need to understand it. In most cases, by looking over the iTunes scripting dictionary (in AppleScript Editor) and trial and error (in AppleScript Editor or with py-appscript) you can figure it out what you want. (Just make sure you're working on a scrap library, or have a backup…) In this case, the only commands it could possibly be are add, copy, duplicate, or move, so just try them all and see what they do. Or, alternatively, go to dougscripts and download a bunch of samples and find one that does what you want.
The second half of this, figuring out how to translate to ScriptingBridge… well, I can't explain it without going into a long rant on SB (which hhas does much better than me, if you want to read one). But the basics are this: As far as iTunes is concerned, duplicate is a command. If you give it a direct object (tell application "iTunes" to duplicate theTrack to thePlaylist) it'll use that; if not, you're asking the subject to duplicate itself (tell theTrack to duplicate to thePlaylist). It works exactly like English. But SB insists on an object-oriented model, where duplicate is a method on some object. So, only one of those two forms is going to work. In general, you can figure out which by just looking at dir(iTunes) and dir(track) to see which one has a method that looks like the command you want.
As you can tell from the above, you've got a lot of trial and error ahead of you if you're trying to do anything complicated. Good luck, and keep asking.
PS, I have no idea why your code fails silently. The obvious way the add_to_ method should translate into a command should raise a -1708 error (as appscript iTunes.add(track, to=newPlaylist) or AppleScript add theTrack to newPlaylist both do…).

python - urls.py regex help with coordinates

I tried searching but could not find an answer for this.
I am trying to write a function that takes in coordinates, ie latitude and longitude. For example, 53.345633,-6.267014.
These will then be fed into the Google Maps API as the users current location, and directions to some nearby places (I already have these locations stored somewhere) and the directions will hopefully be returned.
So, I pretty much have all the Maps work done, but I can't test it because, frustratingly enough, I simply cannot figure out the regex for inside urls.py.
Can anyone help me with this? I'm hoping its simple enough for you guys. I tried it earlier but failed miserably! It's so frustrating coz I'm so close to finishing this part too!!
Thanks for the help!
PS Is the format for coordinates advisable, with the comma? Perhaps 53.345633+-6.267014 would be better (then I can just use my_coords = coords.replace("+", ", ") or something)??
I'm not sure I get it but you can try something like :
def str2cords(scords):
return [float(c) for c in scords.split(',')] #or maybe just scords.split(',') since float might mess up the exact cords?
or regex :
'/(-?\d+\.\d+),(-?\d+\.\d+)/'
If you want the dot to be optional.
(?P<lon>-?\d+.?\d+)/(?P<lat>-?\d+.?\d+)

Categories