简体   繁体   English

Zapier Zap 中的 Python 代码 - 更有效地序列化数据的方法?

[英]Python Code within Zapier Zap - Ways to serialize data more effectively?

Just started with Zapier and building out a few test Zaps to gain a deeper understanding of the capabilities using Zapier for my org.刚开始使用Zapier并构建了一些测试 Zaps,以更深入地了解我的组织使用 Zapier 的功能。

I've run into a few issues with outputs needing to be serialized.我遇到了一些需要序列化输出的问题。 I found a simple fix that passes the output value as a string and it seems to fix the issue in every instance.我找到了一个简单的修复程序,将 output 值作为字符串传递,它似乎在每个实例中都解决了这个问题。 My question is;我的问题是; does anyone have any suggestions on possibly cleaning this up or a better way so I do not have to output data this way?有没有人对可能清理这个或更好的方法有任何建议,所以我不必以这种方式处理 output 数据? Is there anything necessarily wrong with performing the script this way?以这种方式执行脚本是否有任何问题?

Not looking for people literally to re-write my code (unless you'd be open to provide tips for a newbie to python) just looking for some best practice advise.不是从字面上寻找人来重写我的代码(除非您愿意为 python 新手提供提示),只是寻找一些最佳实践建议。

Code:代码:

import re

emails = re.findall(r'[\w._-]+@[\w._-]+\.[\w._-]+', input_data['Payload'])
url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', input_data['Payload'])
tid = re.search('(.*) - This',input_data['PayloadText'])


output = [{'Emails': emails,'URLS': url, 'TemplateID': str(tid)}]

This snipit here;这个片段在这里; 'TemplateID': str(tid) is the code in question. 'TemplateID': str(tid)是有问题的代码。

My output from that snipit is TemplateID <re.Match object; span=(1059, 1070), match='1283 - This'>我的 output 是TemplateID <re.Match object; span=(1059, 1070), match='1283 - This'> TemplateID <re.Match object; span=(1059, 1070), match='1283 - This'>

Please keep in mind I know the script itself could use some hygene!请记住,我知道脚本本身可以使用一些 hygene!

Thanks for any and all assitance!感谢您的帮助!

It really depends what you want to do with the data in later steps.这真的取决于你想在后面的步骤中对数据做什么。 Feeding a string-ified python regex into another step probably won't be super useful?将字符串化的 python 正则表达式输入另一个步骤可能不会超级有用吗? I might try to pull out the actual tempalte id instead ( 1283 ).我可能会尝试提取实际的模板 ID( 1283 )。 You'll also want to be more defensive in case there isn't a match.如果没有比赛,您还需要更加防守。

But to answer your root question: no, there's nothing inherently wrong with passing that string between steps.但是要回答您的根本问题:不,在步骤之间传递该字符串本身并没有错。 All Zapier sees is a string. Zapier 看到的只是一个字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM