Jump to content

LittleEntity

Member
  • Content Count

    20
  • Joined

  • Last visited

  1. thank you for your reply. I live in germany and my native language is german. My System is also configured german. When I use your script it takes an english language locale. What I want is an output like Montag 17.Feb.2014 um 16:39 Uhr Montag (dt.) = Monday (en.) I don't know why it cannot find out my real system's locale. So I decided to manually implement the locale by defining myLocale in the first script. [ locale.setlocale(locale.LC_ALL, '') ] is called in the executed script [ main.py ] in the workflows directory. You don't need to execute it manually in the first script. If you want to use an english locale you can either use [ myLocale = 'en_GB.UTF-8' ] or [ myLocale = locale.getlocale() ]. The last only works properly if you first define [ import locale ] of course. Have fun =) Question to all users: Would you like to have an interface via the Alfred input window to edit your locale and your formats?
  2. new version online! GREEK LOCALE is now supported! download it from the drop box ^^ I don't exactly know how I fixed it but it works with greek letters now. I really need to learn more about encodings and stuff ... I will learn about encodings next week ^^ enjoy the update =) @M1m1s: please write a greek format string to the forums so we can share it for everyone =D thank you. <(^.^)> *cheer!* <(^o^)>
  3. Hi =) I've tried to fix this issue for quite a while now. Right now I cannot find what breaks it. It's something with the Element Tree tostring( ) library function that breaks it. I assume the greek weekday letters contain non ascii symbols. Actually that should be addressed by the tostring( ) method. I'm doing something wrong I guess... I'll try next week to fix it. Got an exam next Monday ^^" thank you for your reply =D PS: fixed some bugs on the way ^^ so it wasn't completely useless =)
  4. def writeFeedback( self ): response = ET.tostring( self.itemsElement, u'UTF-8', u'xml' ) print( response.encode( 'UTF-8' ) ) hmm.. doesn't work either. =( error log: Traceback (most recent call last): File "testing.py", line 8, in <module> feedback.writeFeedback( ) File "/Users/benutzer/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.26FD225E-0254-4E36-996D-B1166C5D36A5/AlfredFeedback.py", line 46, in writeFeedback response = ET.tostring( self.itemsElement, u'UTF-8', u'xml' ) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1127, in tostring return "".join(data) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128) mwahaha ***ROFLMAO*** but guess what? your code WORKS! cannot believe it! awsome !!! how did you know this? you should definitly never stop drinking whish I could spend you a beer some day =D hug >( ^.^)> you <(^.^ )< working piece: def writeFeedback( self ): response = ET.tostring( self.itemsElement ) print( response.encode( 'UTF-8' ) ) so.. the error appears when there is response = ET.tostring( self.itemsElement, u'UTF-8' ) with this version I cannot insert special letters like 'ß' but it will generate the following as first line of the xml: <?xml version='1.0' encoding='UTF-8'?> when I use this one instead: response = ET.tostring( self.itemsElement ) using 'ß' or any other special letter won't break the script but it won't generate the first line with the version and encoding. Alfred works without first line declaring version and encoding =) didn't know that either.
  5. I like you when you are drunk ^^ you seem to become especially helpful. I should advice you to never stop drinking
  6. I edited the files and I still get the same error =( any further suggestions? Thanks alot =) # -*- coding: UTF-8 -*- from __future__ import unicode_literals import xml.etree.ElementTree as ET class AlfredFeedback: itemsElement = ET.Element( u'items' ) def addItem( self, uniqueIdentifier, argument, title, subtitle = None, icon = None, itemtype = None ): uniqueIdentifier = str( uniqueIdentifier ) self.assertUIdenIsNew( uniqueIdentifier ) self.assertValidItemType( itemtype ) itemElement = ET.SubElement( self.itemsElement, u'item' ) itemElement.set( u'uid', uniqueIdentifier ) itemElement.set( u'arg', argument ) if itemtype is not None: itemElement.set( u'type', itemtype ) titleElement = ET.SubElement( itemElement, u'title' ) titleElement.text = title if subtitle is not None: subtitleElement = ET.SubElement( itemElement, u'subtitle' ) subtitleElement.text = subtitle if icon is not None: iconElement = ET.SubElement( itemElement, u'icon' ) iconElement.text = icon def assertUIdenIsNew( self, uniqueIdentifier ): for child in self.itemsElement: if uniqueIdentifier == child.get( u'uid' ): errorString = ( u'the identifier \"' + uniqueIdentifier + u'\" was already added!' ) raise NameError( errorString ) def assertValidItemType( self, itemtype ): if itemtype is not None: if itemtype != u'file': raise Exception( u'The value of parameter itemtype' u'must be a string containing "file"!' ) def writeFeedback( self ): response = ET.tostring( self.itemsElement, u'UTF-8', u'xml' ) print( response ) # -*- coding: UTF-8 -*- from __future__ import unicode_literals from AlfredFeedback import AlfredFeedback feedback = AlfredFeedback( ) feedback.addItem( 1, u'FRST', u'first', u'First Item', u'/path/anIcon.png') feedback.addItem( 2, u'SCND', u'ßecond', u'Second Item', u'/anotherPath/myIcon.png', u'file' ) feedback.writeFeedback( )
  7. If you are using eclipse or sublime text and you have to restructure code like you need to insert a "u" in front of any "'" like in this case, use regular expressions. In sublime text 2 you I used the regex pattern ('.*?') and the replace pattern u\1 . The replace pattern u$1 would have also worked. see http://stackoverflow.com/questions/11819886/regular-expression-search-replace-in-sublime-text-2 for more information =)
  8. that's not true... in line 14 says: uniqueIdentifier = str( uniqueIdentifier ) that's why it works with an integer as argument thankyou very much for your help and effort ^^ I agree with the format changing except that the spaces between '(' and ')' are lost. I am programming with "Times New Roman" because I can read text with not monospaced fonts faster. Sadly when I do this and I do not insert those spaces the code becomes too much condensed which is bad.
  9. I would appreciate any feedback on the workflow and especially on the code. can I embed *.png files to show screenshots somehow?
  10. Here is a AlfredFeedback class I wrote with the etree.ElementTree module for xml handling. This is far easier than the last version x) now... let's speak about utf-8 characters. When I try to insert a 'ß' or 'ä' I get the error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128) which is weird because I set the encoding to 'UTF-8' in line 42 of the AlfredFeedback module. Do you have any advice or suggestions? feedback module code: # -*- coding: UTF-8 -*- import xml.etree.ElementTree as ET class AlfredFeedback: itemsElement = ET.Element( 'items' ) def addItem( self, uniqueIdentifier, argument, title, subtitle = None, icon = None, itemtype = None ): uniqueIdentifier = str( uniqueIdentifier ) self.assertUIdenIsNew( uniqueIdentifier ) self.assertValidItemType( itemtype ) itemElement = ET.SubElement( self.itemsElement, 'item' ) itemElement.set( 'uid', uniqueIdentifier ) itemElement.set( 'arg', argument ) if itemtype is not None: itemElement.set( 'type', itemtype ) titleElement = ET.SubElement( itemElement, 'title' ) titleElement.text = title if subtitle is not None: subtitleElement = ET.SubElement( itemElement, 'subtitle' ) subtitleElement.text = subtitle if icon is not None: iconElement = ET.SubElement( itemElement, 'icon' ) iconElement.text = icon def assertUIdenIsNew( self, uniqueIdentifier ): for child in self.itemsElement: if uniqueIdentifier == child.get( 'uid' ): errorString = 'the identifier \"' + uniqueIdentifier + '\" was already added!' raise NameError(errorString) def assertValidItemType( self, itemtype ): if itemtype is not None: if itemtype != 'file': raise Exception('The value of parameter itemtype must be a string containing "file"!') def writeFeedback( self ): response = ET.tostring( self.itemsElement, 'UTF-8', 'xml' ) print( response ) test code: # -*- coding: UTF-8 -*- from AlfredFeedback import AlfredFeedback feedback = AlfredFeedback( ) feedback.addItem( 1, 'FRST', 'first', 'First Item', '/path/anIcon.png') feedback.addItem( 2, 'SCND', 'ßecond', 'Second Item', '/anotherPath/myIcon.png', 'file' ) feedback.writeFeedback( )
  11. I've already visited the link you posted. And I've already visited some libraries. But for what I wanted to build the libraries are far too complex. I wanted something dead simple to use. Another argument to write my own code and only use the std library is I want to learn python =) Because I am from germany I know how frustrating it can be for users when letters like 'ä' 'ö' 'ü' or 'ß' aren't available for writing names. Here are two links I found which explain how to convert strings to python-xml objects and vice versa: http://stackoverflow.com/questions/3605680/creating-a-simple-xml-file-using-python http://docs.python.org/2/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring
  12. ok, good point. Thankyou for your help =) do you have a link to share explaining how to work with python and XML?
  13. to show others the development I post the error report here: * select file to upload * click upload Result: File doesn't show up. * retry select file to upload * click upload Result: File often shows up * Do this with all upload data * fill out every field with a "*" * click submit Result: Long loading time; redirected to the fill out form; sometimes it resets parts of the form or the form in general * retry all above again Result: sometimes an overlay pops up showing an AJAX error message. Sorry, did not copy it. Currently I don't have more time to spend to go into details or retry everything again or at least get the error message again. I am studying computer science and I know how evil bugs are, which aren't easy to reproduce. I hope you can find some repetitionable errors by examining my report. Sorry again I did not save the error msg =] In any case: great project =D would appreciate to see it working for me.
  14. spent half an hour or more to upload my alfreTS workflow to your site. But it did not work =( cya
×
×
  • Create New...