| 181 | |
| 182 | |
| 183 | def verify_mandatory_words( |
| 184 | mand_words, |
| 185 | comments, |
| 186 | browser, |
| 187 | logger, |
| 188 | ): |
| 189 | if len(mand_words) > 0 or isinstance(comments[0], dict): |
| 190 | try: |
| 191 | post_desc = getMediaData( |
| 192 | "edge_media_to_caption.edges.0.node.text", browser |
| 193 | ).lower() |
| 194 | |
| 195 | except Exception: |
| 196 | post_desc = None |
| 197 | |
| 198 | try: |
| 199 | first_comment = getMediaData( |
| 200 | "edge_media_to_parent_comment.edges.0.node.text", browser |
| 201 | ).lower() |
| 202 | |
| 203 | except Exception: |
| 204 | first_comment = None |
| 205 | |
| 206 | if post_desc is None and first_comment is None: |
| 207 | return False, [], "couldn't get post description and comments" |
| 208 | |
| 209 | text = ( |
| 210 | post_desc |
| 211 | if post_desc is not None |
| 212 | else "" + " " + first_comment |
| 213 | if first_comment is not None |
| 214 | else "" |
| 215 | ) |
| 216 | |
| 217 | if len(mand_words) > 0: |
| 218 | if not evaluate_mandatory_words(text, mand_words): |
| 219 | return False, [], "mandatory words not in post desc" |
| 220 | |
| 221 | if isinstance(comments[0], dict): |
| 222 | # The comments definition is a compound definition of conditions and comments |
| 223 | for compund_comment in comments: |
| 224 | if ( |
| 225 | "mandatory_words" not in compund_comment |
| 226 | or evaluate_mandatory_words( |
| 227 | text, compund_comment["mandatory_words"] |
| 228 | ) |
| 229 | ): |
| 230 | return True, compund_comment["comments"], "Approval" |
| 231 | return ( |
| 232 | False, |
| 233 | [], |
| 234 | "Coulnd't match the mandatory words in any comment definition", |
| 235 | ) |
| 236 | |
| 237 | return True, comments, "Approval" |
| 238 | |
| 239 | |
| 240 | def get_comments_on_post( |