Question

Code by Zapier execute Git

  • 29 March 2023
  • 1 reply
  • 33 views

Userlevel 1

Hello everyone,

I am trying to execute a git that I wrote and posted onto GitHub to have it decentralized. This makes it easier for me to edit the code throughout different zaps without copy and pasting the code every time.

Unfortunately, it does not work, and it causes multiple errors. Most of the time, the errors claim to not have variables defined.


The code used in the Code by Zapier Zapis:
 

import urllib.request

url = 'https://raw.githubusercontent.com/elemosel/GamerGrid-Zap-General/main/General_Code'
response = urllib.request.urlopen(url)
code = response.read().decode()

exec(code)

 

By testing this code it prints out this error: 

 

Your code had an error! Traceback (most recent call last): File "<string>", line 14, in the_function File "<string>", line 34, in <module> File "<string>", line 34, in <genexpr> NameError: name 'inputTextUp' is not defined

 

The code in the Git looks like this: 

 

import re
from io import StringIO
import csv

urlText = input_data['urlText']
date = input_data["date"]
inputText = input_data["Text"]

icons = []
inputTextUp = inputText.upper()

blueIcon = ":large_blue_square:"
greenIcon = ":large_green_square:"
redIcon = ":large_red_square:"
purpleIcon = ":large_purple_square:"
blackIcon = ":black_large_square:"


if "Playstation".upper() in inputTextUp:
icons.append(blueIcon)

if "Xbox".upper() in inputTextUp:
icons.append(greenIcon)

if "Nintendo".upper() in inputTextUp:
icons.append(redIcon)

if "PC".upper() in inputTextUp:
icons.append(blackIcon)

if "Mobile".upper() in inputTextUp:
icons.append(purpleIcon)

if all(substring.upper() not in inputTextUp for substring in ["PC", "Mobile", "Nintendo", "Xbox", "Playstation"]):
icons.append(blueIcon)
icons.append(greenIcon)
icons.append(redIcon)
icons.append(blackIcon)
icons.append(purpleIcon)


urls = urlText.split(",")

# Replace all occurrences of '/' with an date
date = date.replace('/', '_')

# Replace all occurrences of ':' with an date
date = date.replace(':', '-')

date = date.replace(' ', '+')

output = {"date": date, "urls": urls, "icons": icons}


for key,value in output.items():
value = ''.join(str(x) for x in value)
print("\n" + key + " => " + value )

Can someone help me wit this issue ?

Best regards 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Userlevel 7
Badge +11

Hey there @GamerGrid! 👋

I don’t think it’s possible to use a Code by Zapier action to import that code, as it’s not currently possible to “require external libraries, or install or import libraries”. See Limitations with Code steps.

Instead, perhaps you could you store the code that you wanted to re-use inside a Sub-Zap? That way you could re-use across multiple Zaps. You can find out more about how to work with SubZaps here: Build reusable Sub-Zaps

Hope that helps! 🙂