Jump to content

LittleEntity

Member
  • Posts

    20
  • Joined

  • Last visited

Posts posted by LittleEntity

  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 ^^

     

    Download the current package via dropbox.

     

    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 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( )
    
    
  6. 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 =)

  7.  

    There are 2 problems with the script.

     

    Firstly, your addItem method will only accept unicode/strings, so:

    feedback.addItem( 1, ...)
    

    needs to be:

    feedback.addItem( '1', ...)
    

    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.

  8. 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( )
    
  9. 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

  10. 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.

  11. (...)

     

    In a language like Python, PHP, Ruby or anything else that has built-in XML support, you should probably use those feature to generate your output. If you don't, sooner or later you'll end up with & or < or > in your output, which will break Alfred (invalid XML).

     

    thankyou for your helpful reply =D what do you mean with '<' in the output? You mean escaping '<' signs in text content?

  12. alfreTS

    This is a time stamp workflow for the Alfred Application.

     

    Download the current package via dropbox.

     

    Open the alfred window then type now. The results show the current timestamp in different formats. Select a timestamp format to copy the shown timestamp to the clipboard. Paste it into any editor you like.

     

    You can define your own formats via the python strftime syntax. It is also possible to define your preferred locale setting to acquire the weekday and month names in your local language. In order to edit these settings you need to enter the settings into the script of the Script Filter inside the workflow. This can be done by editing the #commented lines. (In case you did not know how #comments work: lines with # in front will be ignored by the python interpreter and not be executed.)

     

    Please visit the projects github repository.

     

    If you are using this workflow and you happen to make a new format for timestamps please share it here. Thankyou!

     

    <( ^_^)> hug me <(^.^ )>

     

    PS: somehow I cannot add screenshots here. It says I am not allowed to link *.png files  (T_T)"  If you would like to see some screenshots please visit the github repository. The README.md contains two screenshots.

     

    update: new version online =) alfreTS_v0.0.201402142154.alfredworkflow

     

    Question to all users: Would you like to have an interface via the Alfred input window to edit your locale and your formats?

  13. What is the "type" attribute used for? is it optional? if it is this should be pointed out in the post =) (I'm assuming that it is optional)

    When I set the value to "file": what is the advantage for Alfred/Alfred's user?

    The Format

    (...)

    type

    The type attribute allows you to specify what type of result you are generating. Currently, the only value available for this attribute is file. This will allow you to specify that the feedback item is a file and allows you to use Result Actions on the feedback item.

    (...)
  14. lol... I thought they were needed to tell alfred that a msg block is coming. I copied them from the shell Example. Can somebody explain, why they are need in the example?

    Thankyou for the fast reply.

     

    Shell example "Script Filter XML format":

    cat << EOB
    
    <?xml version="1.0"?>
    
    <items>
    
    <!--
      Example of using icon type 'fileicon' to load the file icon directly.
      This item is of type "file" which means it will be treated as a file in
      Alfred's results, so can be actioned and revealed in finder.
      Autocomplete sets what will complete when the user autocompletes.
    -->
    
      <item uid="desktop" arg="~/Desktop" valid="YES" autocomplete="Desktop" type="file">
        <title>Desktop</title>
        <subtitle>~/Desktop</subtitle>
        <icon type="fileicon">~/Desktop</icon>
      </item>
    
    <!--
      Example of loading an icon from the Workflow's folder.
      This item is set as valid no, which means it won't be actioned
    -->
    
      <item uid="flickr" valid="no" autocomplete="flickr">
        <title>Flickr</title>
        <icon>flickr.png</icon>
      </item>
    
    <!--
      Example of using icon type 'filetype' to load the icon for the file type.
      This item is of type "file" which means it will be treated as a file in
      Alfred's results, so can be actioned and revealed in finder.
    -->
    
      <item uid="image" autocomplete="My holiday photo" type="file">
        <title>My holiday photo</title>
        <subtitle>~/Pictures/My holiday photo.jpg</subtitle>
        <icon type="filetype">public.jpeg</icon>
      </item>
    
    </items>
    
    EOB
  15. Hallo

     

    I am fiddling  since 5 hours now and still cannot make anything work =(

    minimized my testing to the following:

    xml = 'EOB' '\n\n'
    xml += '<?xml version="1.0"?>' '\n'
    xml += '<items>' '\n'
    xml += '\t' '<item uid="whatever" arg="myResult">' '\n'
    xml += '\t' '\t' '<title>hallo</title>' '\n'
    xml += '\t' '\t' '<subtitle>who is there?</subtitle>' '\n'
    xml += '\t' '</item>' '\n'
    xml += '</items>'
    xml += '\n\nEOB'
    
    print(xml)
    

    I used a script filter.

    Tried to paste it into the window, while selecting the python interpreter.

    Tried to use the bash shell interpreter with "python myScriptname.py".

     

    Any help appreciated. Is there any Tutorial on this topic? Cannot find appropriate documentation either =( Am I blind? Sorry if I could not find a proper documentation when there is one out there...

×
×
  • Create New...