Skip to content

Instantly share code, notes, and snippets.

@begin29
Last active June 20, 2019 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save begin29/ad44d7db60581aa51aedc3d241be7506 to your computer and use it in GitHub Desktop.
Save begin29/ad44d7db60581aa51aedc3d241be7506 to your computer and use it in GitHub Desktop.
def match_urls_in_cities(file_names)
cities_count = {}
file_names.each do |file_name|
File.open(file_name, "r") do |f|
f.each_line do |line|
city_name = line.match(/(.*)\t/)[0].gsub("\t", "")
cities_count[city_name] ||= 0
cities_count[city_name] += 1 if is_url_present?(line)
end
end
end
p cities_count
end
private
def is_url_present?(line)
line.match(/(http[s]?\:\/\/)[a-z0-9._]+/).tap do |matched_val|
return true if matched_val
end
return false
end
match_urls_in_cities(["tweets_aa", "tweets_ab", "tweets_ac"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment