def check_created_image_regex(first_image_url, second_image_url, regex): matches = Regex.Matches(first_page_source._source, regex, RegexOptions.IgnoreCase) escaped_first_image_url = escape_uri_string(first_image_url) escaped_second_image_url = escape_uri_string(second_image_url) if matches.Count == 0: return False, 0 else: if debug: print "\nFound " + str( matches.Count ) + " match(es) on the first page with regex: " + regex print "Captured: " + matches[0].Value print "link group: " + matches[0].Groups["link"].Value #We don't care if there is more than one result. As long as the first result is the correct image result, image_uri = Uri.TryCreate(first_page_uri, matches[0].Groups["link"].Value) #Valid url and matches the input image url if result and image_uri.AbsoluteUri in (first_image_url, escaped_first_image_url): if debug: print "Valid uri and matches image url" else: if debug: print "Not a valid uri or doesn't match image url" return False, 0 matches_second = Regex.Matches(second_page_source._source, regex, RegexOptions.IgnoreCase) if matches_second.Count == 0: if debug: print "No matches on the second page" return False, 0 #Regex match on the second page. Same deal as above. We don't care if there is more than one result if debug: print "\nFound " + str( matches_second.Count) + " match(es) on the second page" print "Captured: " + matches_second[0].Value print "link group: " + matches_second[0].Groups["link"].Value result, image_uri = Uri.TryCreate( second_page_uri, matches_second[0].Groups["link"].Value) if result and image_uri.AbsoluteUri in (second_image_url, escaped_second_image_url): if debug: print "Regex works on both pages and returns the correct image" return True, matches.Count else: if debug: print "Invalid Uri or doesn't match the second image url" return False, 0 return False, matches.Count
def check_regex_against_source(regex, check_value, check_value2): matches = Regex.Matches(first_page_source._source, regex._regex, RegexOptions.IgnoreCase) if matches.Count != 0: if debug: print "\n\nFound " + str( matches.Count ) + " match(es) on the first page with regex: " + regex._regex print "Captured: " + matches[0].Value print "link group: " + matches[0].Groups["link"].Value #We don't care if there is more than one result. As long as the first result is the correct image result, result_uri = Uri.TryCreate(first_page_uri, matches[0].Groups["link"].Value) if result and result_uri.AbsoluteUri in (check_value, check_value2): #Valid url and matches against the check_value if debug: print "Valid uri" else: return False matches_second = Regex.Matches(second_page_source._source, regex._regex, RegexOptions.IgnoreCase) if matches_second.Count == 0: if debug: print "No matches found on the second page" return False #Regex match on the second page. Same deal as above. We don't care if there is more than one result if debug: print "\nFound " + str( matches_second.Count) + " match(es) on the second page" print "Captured: " + matches_second[0].Value print "link group: " + matches_second[0].Groups["link"].Value result, result_uri = Uri.TryCreate( second_page_uri, matches_second[0].Groups["link"].Value) if result: regex._matches = matches.Count if debug: print "Added to valid regex" return regex else: if debug: print "Invalid uri" return False return False
def onDrawClipboard(s, e): global uriList if s == Application.Current.MainWindow: text = tryGetClipboardText() if text is not None: match = Regex.Match(text, "(\\S+)://([^:/]+)(:(\\d+))?(/[^#\\s]*)(#(\\S+))?", RegexOptions.CultureInvariant); if match.Success: success, uri = Uri.TryCreate(match.Value, UriKind.RelativeOrAbsolute) if success: if uri.IsAbsoluteUri and uriList.Contains(uri) == False: if not uri.Host.Equals("nazr.in"): uriList.Add(uri) if uriList.Count > 10: uriList.RemoveRange(0, uriList.Count - 10)