Editorial Workflows

Supermarket Route

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: This routine orders a given supermarket list based on another master section/article list that you can build by yourself, and creates a task paper file with your planned purchase route nicely distributed by sections, and in the order that you usually traverse the supermarket, which is the order that you specify in your master list. The problem that this routine helps to solve is the following: at the moment when you trap the list of things that you need to purchase, you usually don't have in mind the order in which the supermarket places the articles into sections. You just drop you items as they come to your memory. Later, when you are at the supermarket, and you use your unordered list, you have to go up and down through it (unless you have memorized it) , and sometimes you miss an article and you have to step back through your route to get it. This routine can help you to avoid that very common situation among golden fishes like we many people are.

The routine is thought so you can use it for more than one supermarket.

To use this routine, first, you create a file with your shopping list formatted in the following fashion:

MySupermarket @supermarket
List:
Article 1
Article 2
Article 3:amount 3
...
...

First and second lines are mandatory. First line contains the name of the supermarket that you want to have the list ordered for. You will see below why you need this line. The second line is just to tell to the routine that the list goes after the second line. After that, you will enter the items of your shopping list, and opcionalliy the amount of each items after a colon.

Once you have your shopping list, you will create a subdirectory called "super" in the same directory where you have your shopping list. You will have to do this only once.

Into that subdirectory, you create a file called "MySupermarket.taskpaper". This file will contain the section/article ordered distribution that represents the route that you follow during your shopping. Note that the name of the file must be the same as the name of the supermarket of the first line in your shop list. You can have as many supermarket files as you want in your "super " subdirectory. The routine will reorder your shopping list using the file with the name in the first line of your shopping list.

The content of the file "MySupermarket.taskpaper" (here is where you enter your shopping route) that you create will have the following structure:

Section 1:
article 3
Section 2:
article 2
article 1
...
...

All section names must end with colons.
Note that the names of the articles must be lowercase, and notice that you should not write dashes behind the article names (you are not creating a task list; the routine will do that for you).

Once you have a master sorted out, just execute the workflow routine from you shopping list file, and the routine will create the task list shopping route for you.

One last thing: the articles that the routine cannot find in your master list will be placed in an special section called "No section" at the end.

Happy shopping!

Shared by: Rafa Sanchez

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Set Variable ?
Variable Name
encargo
Value
Get Super Path Name ?
Source Code
#coding: utf-8
import workflow
import editor
import os
import re
import console

action_in = workflow.get_input()

#TODO: Generate the output...
action_out = action_in
noSection='No section'

fullpath=editor.get_path()
path=os.path.dirname(fullpath)
path=os.path.join(path,'super')
encargo=editor.get_text()
match=re.match('(\w+) .*@supermarket.*\n',encargo)
reEndingColon=re.compile('(.*):')
if match is None:
	console.hud_alert('No hay une linea con el supermercado')
	workflow.set_output('')
	quit()
	
supername=match.group(1)
superpath=os.path.join(path,supername+'.taskpaper')
prog=re.compile('.*\nList:\n(.*)',re.S)
match=prog.match(encargo)
if match is None:
	console.hud_alert('No hay nada en la lista del encargo')
	workflow.set_output('')
	quit()

lista=match.group(1).split('\n')
superDict=dict()
superKeys=dict()
superList=[]
curSection=noSection
with open(superpath,'r') as superFile:
	for l in superFile:
		match=reEndingColon.match(l)
		if match is None:
			articulo=l.rstrip('\n\r').lower()
			superDict[articulo]=curSection
		else:
			curSection=match.group(1)
			superList.append([curSection,[]])
			superKeys[curSection]=len(superList)-1
			
superList.append([noSection,[]])
superKeys[noSection]=len(superList)-1
for artycant in lista:
	splited=artycant.split(':')
	articulo=splited[0].rstrip('\n\r').lower()
	if articulo in superDict.keys():
		superList[superKeys[superDict[articulo.encode('utf-8')]]][1].append(artycant)
	else:
		superList[superKeys[noSection]][1].append(artycant)

outputList=[]
for section in superList:
	outputList.append(section[0]+':\n')
	for item in section[1]:
		outputList.append('- '+item+'\n')
output=''.join(outputList)
workflow.set_variable('encargo',output)
workflow.set_output(output)
Create Document ?
Filename
supermarketRoute.taskpaper
Content
encargo
Open in Editor
ON