MCPcopy
hub / github.com/InstaPy/InstaPy / evaluate_mandatory_words

Function evaluate_mandatory_words

instapy/util.py:105–125  ·  view source on GitHub ↗
(text, mandatory_words_list, level=0)

Source from the content-addressed store, hash-verified

103
104# Evaluate a mandatory words list against a text
105def evaluate_mandatory_words(text, mandatory_words_list, level=0):
106 if level % 2 == 0:
107 # this is an "or" level so at least one of the words of compound sub-conditions should match
108 for word in mandatory_words_list:
109 if isinstance(word, list):
110 res = evaluate_mandatory_words(text, word, level + 1)
111 if res:
112 return True
113 elif word.lower() in text:
114 return True
115 return False
116 else:
117 # this is an "and" level so all of the words and compound sub-conditions must match
118 for word in mandatory_words_list:
119 if isinstance(word, list):
120 res = evaluate_mandatory_words(text, word, level + 1)
121 if not res:
122 return False
123 elif word.lower() not in text:
124 return False
125 return True
126
127
128def validate_username(

Callers 4

verify_mandatory_wordsFunction · 0.85
validate_usernameFunction · 0.85
check_linkFunction · 0.85

Calls

no outgoing calls

Tested by 1