DEV: Format .thor files (#23059)
This commit is contained in:
parent
5e72f2a342
commit
8bebd8fd99
|
@ -73,7 +73,7 @@ jobs:
|
||||||
if: ${{ !cancelled() }}
|
if: ${{ !cancelled() }}
|
||||||
run: |
|
run: |
|
||||||
set -E
|
set -E
|
||||||
bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake')
|
bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake') $(git ls-files '*.thor')
|
||||||
|
|
||||||
- name: ESLint (core)
|
- name: ESLint (core)
|
||||||
if: ${{ !cancelled() }}
|
if: ${{ !cancelled() }}
|
||||||
|
|
|
@ -4,13 +4,11 @@ class Backfill < Thor
|
||||||
desc "link_titles", "Backfills link titles"
|
desc "link_titles", "Backfills link titles"
|
||||||
|
|
||||||
def link_titles
|
def link_titles
|
||||||
require './config/environment'
|
require "./config/environment"
|
||||||
topic_links = TopicLink.where(crawled_at: nil, internal: false)
|
topic_links = TopicLink.where(crawled_at: nil, internal: false)
|
||||||
|
|
||||||
puts "Enqueueing Topic Links: #{topic_links.count} links found."
|
puts "Enqueueing Topic Links: #{topic_links.count} links found."
|
||||||
|
|
||||||
topic_links.pluck(:id).each do |tl|
|
topic_links.pluck(:id).each { |tl| Jobs.enqueue(:crawl_topic_link, topic_link_id: tl) }
|
||||||
Jobs.enqueue(:crawl_topic_link, topic_link_id: tl)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,14 +21,28 @@ class Populate < Thor
|
||||||
> $ thor populate:posts -p 10 -n 5
|
> $ thor populate:posts -p 10 -n 5
|
||||||
|
|
||||||
MD
|
MD
|
||||||
method_option :num_posts, aliases: '-n', type: :numeric, required: true, desc: "Number of posts to make"
|
method_option :num_posts,
|
||||||
method_option :users, aliases: '-u', type: :array, desc: "Usernames of users who will make the posts"
|
aliases: "-n",
|
||||||
method_option :title, aliases: '-t', desc: "The title of the topic, if making a new topic"
|
type: :numeric,
|
||||||
method_option :topic_id, aliases: '-i', type: :numeric, desc: "The id of the topic where the posts will be added"
|
required: true,
|
||||||
method_option :num_topics, aliases: '-p', type: :numeric, default: 1, desc: "Number of topics to create"
|
desc: "Number of posts to make"
|
||||||
|
method_option :users,
|
||||||
|
aliases: "-u",
|
||||||
|
type: :array,
|
||||||
|
desc: "Usernames of users who will make the posts"
|
||||||
|
method_option :title, aliases: "-t", desc: "The title of the topic, if making a new topic"
|
||||||
|
method_option :topic_id,
|
||||||
|
aliases: "-i",
|
||||||
|
type: :numeric,
|
||||||
|
desc: "The id of the topic where the posts will be added"
|
||||||
|
method_option :num_topics,
|
||||||
|
aliases: "-p",
|
||||||
|
type: :numeric,
|
||||||
|
default: 1,
|
||||||
|
desc: "Number of topics to create"
|
||||||
|
|
||||||
def posts
|
def posts
|
||||||
require './config/environment'
|
require "./config/environment"
|
||||||
users = []
|
users = []
|
||||||
if options[:users]
|
if options[:users]
|
||||||
options[:users].each do |u|
|
options[:users].each do |u|
|
||||||
|
@ -49,10 +63,8 @@ class Populate < Thor
|
||||||
topic = create_topic(users) unless topic
|
topic = create_topic(users) unless topic
|
||||||
puts "Adding posts to '#{topic.title}'"
|
puts "Adding posts to '#{topic.title}'"
|
||||||
puts "Making #{options[:num_posts]} posts"
|
puts "Making #{options[:num_posts]} posts"
|
||||||
(start_post..options[:num_posts]).each do
|
(start_post..options[:num_posts]).each { create_post(users, topic) }
|
||||||
create_post(users, topic)
|
puts ""
|
||||||
end
|
|
||||||
puts ''
|
|
||||||
puts "Done. Topic id = #{topic.id}"
|
puts "Done. Topic id = #{topic.id}"
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
|
@ -65,7 +77,12 @@ class Populate < Thor
|
||||||
user = User.find_by_email(user_email)
|
user = User.find_by_email(user_email)
|
||||||
unless user
|
unless user
|
||||||
puts "Creating new account: #{user_email}"
|
puts "Creating new account: #{user_email}"
|
||||||
user = User.create!(email: user_email, password: SecureRandom.hex, username: UserNameSuggester.suggest(user_email))
|
user =
|
||||||
|
User.create!(
|
||||||
|
email: user_email,
|
||||||
|
password: SecureRandom.hex,
|
||||||
|
username: UserNameSuggester.suggest(user_email),
|
||||||
|
)
|
||||||
end
|
end
|
||||||
user.active = true
|
user.active = true
|
||||||
user.save!
|
user.save!
|
||||||
|
@ -87,35 +104,158 @@ class Populate < Thor
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_post(users, topic)
|
def create_post(users, topic)
|
||||||
print '.'
|
print "."
|
||||||
raw = rand(4) == 0 ? (rand(2) == 0 ? image_posts.sample : wikipedia_posts.sample) : generate_sentence(7)
|
raw =
|
||||||
|
(
|
||||||
|
if rand(4) == 0
|
||||||
|
(rand(2) == 0 ? image_posts.sample : wikipedia_posts.sample)
|
||||||
|
else
|
||||||
|
generate_sentence(7)
|
||||||
|
end
|
||||||
|
)
|
||||||
post_creator = PostCreator.new(users.sample, topic_id: topic.id, raw: raw)
|
post_creator = PostCreator.new(users.sample, topic_id: topic.id, raw: raw)
|
||||||
post = post_creator.create
|
post = post_creator.create
|
||||||
unless post
|
puts post_creator.errors.full_messages, "" unless post
|
||||||
puts post_creator.errors.full_messages, ""
|
|
||||||
end
|
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
def hipster_words
|
def hipster_words
|
||||||
@hipster_words ||= ['etsy', 'twee', 'hoodie', 'Banksy', 'retro', 'synth', 'single-origin', 'coffee', 'art', 'party', 'cliche', 'artisan', 'Williamsburg', 'squid', 'helvetica', 'keytar', 'American Apparel', 'craft beer', 'food truck', "you probably haven't heard of them", 'cardigan', 'aesthetic', 'raw denim', 'sartorial', 'gentrify', 'lomo', 'Vice', 'Pitchfork', 'Austin', 'sustainable', 'salvia', 'organic', 'thundercats', 'PBR', 'iPhone', 'lo-fi', 'skateboard', 'jean shorts', 'next level', 'beard', 'tattooed', 'trust fund', 'Four Loko', 'master cleanse', 'ethical', 'high life', 'wolf moon', 'fanny pack', 'Terry Richardson', '8-bit', 'Carles', 'Shoreditch', 'seitan', 'freegan', 'keffiyeh', 'biodiesel', 'quinoa', 'farm-to-table', 'fixie', 'viral', 'chambray', 'scenester', 'leggings', 'readymade', 'Brooklyn', 'Wayfarers', 'Marfa', 'put a bird on it', 'dreamcatcher', 'photo booth', 'tofu', 'mlkshk', 'vegan', 'vinyl', 'DIY', 'banh mi', 'bicycle rights', 'before they sold out', 'gluten-free', 'yr butcher blog', 'whatever', '+1', 'Cosby Sweater', 'VHS', 'messenger bag', 'cred', 'locavore', 'mustache', 'tumblr', 'Portland', 'mixtape', 'fap', 'letterpress', "McSweeney's", 'stumptown', 'brunch', 'Wes Anderson', 'irony', 'echo park']
|
@hipster_words ||= [
|
||||||
|
"etsy",
|
||||||
|
"twee",
|
||||||
|
"hoodie",
|
||||||
|
"Banksy",
|
||||||
|
"retro",
|
||||||
|
"synth",
|
||||||
|
"single-origin",
|
||||||
|
"coffee",
|
||||||
|
"art",
|
||||||
|
"party",
|
||||||
|
"cliche",
|
||||||
|
"artisan",
|
||||||
|
"Williamsburg",
|
||||||
|
"squid",
|
||||||
|
"helvetica",
|
||||||
|
"keytar",
|
||||||
|
"American Apparel",
|
||||||
|
"craft beer",
|
||||||
|
"food truck",
|
||||||
|
"you probably haven't heard of them",
|
||||||
|
"cardigan",
|
||||||
|
"aesthetic",
|
||||||
|
"raw denim",
|
||||||
|
"sartorial",
|
||||||
|
"gentrify",
|
||||||
|
"lomo",
|
||||||
|
"Vice",
|
||||||
|
"Pitchfork",
|
||||||
|
"Austin",
|
||||||
|
"sustainable",
|
||||||
|
"salvia",
|
||||||
|
"organic",
|
||||||
|
"thundercats",
|
||||||
|
"PBR",
|
||||||
|
"iPhone",
|
||||||
|
"lo-fi",
|
||||||
|
"skateboard",
|
||||||
|
"jean shorts",
|
||||||
|
"next level",
|
||||||
|
"beard",
|
||||||
|
"tattooed",
|
||||||
|
"trust fund",
|
||||||
|
"Four Loko",
|
||||||
|
"master cleanse",
|
||||||
|
"ethical",
|
||||||
|
"high life",
|
||||||
|
"wolf moon",
|
||||||
|
"fanny pack",
|
||||||
|
"Terry Richardson",
|
||||||
|
"8-bit",
|
||||||
|
"Carles",
|
||||||
|
"Shoreditch",
|
||||||
|
"seitan",
|
||||||
|
"freegan",
|
||||||
|
"keffiyeh",
|
||||||
|
"biodiesel",
|
||||||
|
"quinoa",
|
||||||
|
"farm-to-table",
|
||||||
|
"fixie",
|
||||||
|
"viral",
|
||||||
|
"chambray",
|
||||||
|
"scenester",
|
||||||
|
"leggings",
|
||||||
|
"readymade",
|
||||||
|
"Brooklyn",
|
||||||
|
"Wayfarers",
|
||||||
|
"Marfa",
|
||||||
|
"put a bird on it",
|
||||||
|
"dreamcatcher",
|
||||||
|
"photo booth",
|
||||||
|
"tofu",
|
||||||
|
"mlkshk",
|
||||||
|
"vegan",
|
||||||
|
"vinyl",
|
||||||
|
"DIY",
|
||||||
|
"banh mi",
|
||||||
|
"bicycle rights",
|
||||||
|
"before they sold out",
|
||||||
|
"gluten-free",
|
||||||
|
"yr butcher blog",
|
||||||
|
"whatever",
|
||||||
|
"+1",
|
||||||
|
"Cosby Sweater",
|
||||||
|
"VHS",
|
||||||
|
"messenger bag",
|
||||||
|
"cred",
|
||||||
|
"locavore",
|
||||||
|
"mustache",
|
||||||
|
"tumblr",
|
||||||
|
"Portland",
|
||||||
|
"mixtape",
|
||||||
|
"fap",
|
||||||
|
"letterpress",
|
||||||
|
"McSweeney's",
|
||||||
|
"stumptown",
|
||||||
|
"brunch",
|
||||||
|
"Wes Anderson",
|
||||||
|
"irony",
|
||||||
|
"echo park",
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_sentence(num_words)
|
def generate_sentence(num_words)
|
||||||
sentence = hipster_words.sample(num_words).join(' ').capitalize + '.'
|
sentence = hipster_words.sample(num_words).join(" ").capitalize + "."
|
||||||
sentence.force_encoding('UTF-8')
|
sentence.force_encoding("UTF-8")
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_email
|
def generate_email
|
||||||
email = hipster_words.sample.delete(' ') + '@' + hipster_words.sample.delete(' ') + '.com'
|
email = hipster_words.sample.delete(" ") + "@" + hipster_words.sample.delete(" ") + ".com"
|
||||||
email.delete("'").force_encoding('UTF-8')
|
email.delete("'").force_encoding("UTF-8")
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_posts
|
def image_posts
|
||||||
@image_posts ||= ["http://i.imgur.com/CnRF48R.jpg\n\n", "http://i.imgur.com/2iaeK.png\n\n", "http://i.imgur.com/WSD5t61.jpg\n\n", "http://i.imgur.com/GUldmUd.jpg\n\n", "http://i.imgur.com/nJnb6Bj.jpg\n\n", "http://i.imgur.com/eljDYjm.jpg\n\n", "http://i.imgur.com/5yZMWyY.png\n\n", "http://i.imgur.com/2iCPGm2.jpg\n\n"]
|
@image_posts ||= [
|
||||||
|
"http://i.imgur.com/CnRF48R.jpg\n\n",
|
||||||
|
"http://i.imgur.com/2iaeK.png\n\n",
|
||||||
|
"http://i.imgur.com/WSD5t61.jpg\n\n",
|
||||||
|
"http://i.imgur.com/GUldmUd.jpg\n\n",
|
||||||
|
"http://i.imgur.com/nJnb6Bj.jpg\n\n",
|
||||||
|
"http://i.imgur.com/eljDYjm.jpg\n\n",
|
||||||
|
"http://i.imgur.com/5yZMWyY.png\n\n",
|
||||||
|
"http://i.imgur.com/2iCPGm2.jpg\n\n",
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def wikipedia_posts
|
def wikipedia_posts
|
||||||
@wikipedia_posts ||= ["http://en.wikipedia.org/wiki/Dwarf_fortress\n\n", "http://en.wikipedia.org/wiki/Action_plan\n\n", "http://en.wikipedia.org/wiki/Chang%27e_3\n\n", "http://en.wikipedia.org/wiki/Carl_sagan\n\n", "http://en.wikipedia.org/wiki/Chasmosaurus\n\n", "http://en.wikipedia.org/wiki/Indian_Space_Research_Organisation\n\n", "http://en.wikipedia.org/wiki/Rockstar_Consortium\n\n", "http://en.wikipedia.org/wiki/Manitoulin_island\n\n"]
|
@wikipedia_posts ||= [
|
||||||
|
"http://en.wikipedia.org/wiki/Dwarf_fortress\n\n",
|
||||||
|
"http://en.wikipedia.org/wiki/Action_plan\n\n",
|
||||||
|
"http://en.wikipedia.org/wiki/Chang%27e_3\n\n",
|
||||||
|
"http://en.wikipedia.org/wiki/Carl_sagan\n\n",
|
||||||
|
"http://en.wikipedia.org/wiki/Chasmosaurus\n\n",
|
||||||
|
"http://en.wikipedia.org/wiki/Indian_Space_Research_Organisation\n\n",
|
||||||
|
"http://en.wikipedia.org/wiki/Rockstar_Consortium\n\n",
|
||||||
|
"http://en.wikipedia.org/wiki/Manitoulin_island\n\n",
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'open-uri'
|
require "open-uri"
|
||||||
|
|
||||||
class Typepad < Thor
|
class Typepad < Thor
|
||||||
|
|
||||||
desc "import", "Imports posts from a Disqus XML export"
|
desc "import", "Imports posts from a Disqus XML export"
|
||||||
method_option :file, aliases: '-f', required: true, desc: "The typepad file to import"
|
method_option :file, aliases: "-f", required: true, desc: "The typepad file to import"
|
||||||
method_option :post_as, aliases: '-p', required: true, desc: "The Discourse username to post as"
|
method_option :post_as, aliases: "-p", required: true, desc: "The Discourse username to post as"
|
||||||
method_option :google_api, aliases: '-g', required: false, desc: "The google plus API key to use to fetch usernames"
|
method_option :google_api,
|
||||||
|
aliases: "-g",
|
||||||
|
required: false,
|
||||||
|
desc: "The google plus API key to use to fetch usernames"
|
||||||
|
|
||||||
def import
|
def import
|
||||||
require './config/environment'
|
require "./config/environment"
|
||||||
|
|
||||||
backup_settings = {}
|
backup_settings = {}
|
||||||
%w(blocked_email_domains).each do |s|
|
%w[blocked_email_domains].each { |s| backup_settings[s] = SiteSetting.get(s) }
|
||||||
backup_settings[s] = SiteSetting.get(s)
|
|
||||||
end
|
|
||||||
|
|
||||||
user = User.where(username_lower: options[:post_as].downcase).first
|
user = User.where(username_lower: options[:post_as].downcase).first
|
||||||
if user.nil?
|
if user.nil?
|
||||||
|
@ -31,26 +31,24 @@ class Typepad < Thor
|
||||||
input = ""
|
input = ""
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
File.open(options[:file]).each_line do |l|
|
File
|
||||||
l = l.scrub
|
.open(options[:file])
|
||||||
|
.each_line do |l|
|
||||||
|
l = l.scrub
|
||||||
|
|
||||||
if l =~ /\A--------\z/
|
if l =~ /\A--------\z/
|
||||||
parsed_entry = process_entry(input)
|
parsed_entry = process_entry(input)
|
||||||
if parsed_entry
|
if parsed_entry
|
||||||
puts "Parsed #{parsed_entry[:title]}"
|
puts "Parsed #{parsed_entry[:title]}"
|
||||||
entries << parsed_entry
|
entries << parsed_entry
|
||||||
|
end
|
||||||
|
input = ""
|
||||||
|
else
|
||||||
|
input << l
|
||||||
end
|
end
|
||||||
input = ""
|
|
||||||
else
|
|
||||||
input << l
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
entries.each_with_index do |e, i|
|
entries.each_with_index { |e, i| puts "#{i}: #{e[:title]}" if e[:title] =~ /Head/ }
|
||||||
if e[:title] =~ /Head/
|
|
||||||
puts "#{i}: #{e[:title]}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
RateLimiter.disable
|
RateLimiter.disable
|
||||||
SiteSetting.blocked_email_domains = ""
|
SiteSetting.blocked_email_domains = ""
|
||||||
|
@ -74,13 +72,23 @@ class Typepad < Thor
|
||||||
email = c[:email]
|
email = c[:email]
|
||||||
post_user = User.where(email: email).first
|
post_user = User.where(email: email).first
|
||||||
if post_user.blank?
|
if post_user.blank?
|
||||||
post_user = User.create!(name: c[:name], email: email, username: UserNameSuggester.suggest(username))
|
post_user =
|
||||||
|
User.create!(
|
||||||
|
name: c[:name],
|
||||||
|
email: email,
|
||||||
|
username: UserNameSuggester.suggest(username),
|
||||||
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
post_user = User.where(username: username).first
|
post_user = User.where(username: username).first
|
||||||
if post_user.blank?
|
if post_user.blank?
|
||||||
suggested = UserNameSuggester.suggest(username)
|
suggested = UserNameSuggester.suggest(username)
|
||||||
post_user = User.create!(name: c[:name], email: "#{suggested}@no-email-found.com", username: suggested)
|
post_user =
|
||||||
|
User.create!(
|
||||||
|
name: c[:name],
|
||||||
|
email: "#{suggested}@no-email-found.com",
|
||||||
|
username: suggested,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -89,7 +97,7 @@ class Typepad < Thor
|
||||||
raw: c[:body],
|
raw: c[:body],
|
||||||
cooked: c[:body],
|
cooked: c[:body],
|
||||||
created_at: c[:date],
|
created_at: c[:date],
|
||||||
skip_validations: true
|
skip_validations: true,
|
||||||
}
|
}
|
||||||
begin
|
begin
|
||||||
post = PostCreator.new(post_user, attrs).create
|
post = PostCreator.new(post_user, attrs).create
|
||||||
|
@ -100,35 +108,34 @@ class Typepad < Thor
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
RateLimiter.enable
|
RateLimiter.enable
|
||||||
backup_settings.each do |s, v|
|
backup_settings.each { |s, v| SiteSetting.set(s, v) }
|
||||||
SiteSetting.set(s, v)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def clean_type!(type)
|
def clean_type!(type)
|
||||||
type.downcase!
|
type.downcase!
|
||||||
type.gsub!(/ /, '_')
|
type.gsub!(/ /, "_")
|
||||||
type
|
type
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_meta_data(section)
|
def parse_meta_data(section)
|
||||||
result = {}
|
result = {}
|
||||||
section.split(/\n/).each do |l|
|
section
|
||||||
if l =~ /\A([A-Z\ ]+)\: (.*)\z/
|
.split(/\n/)
|
||||||
key, value = Regexp.last_match[1], Regexp.last_match[2]
|
.each do |l|
|
||||||
clean_type!(key)
|
if l =~ /\A([A-Z\ ]+)\: (.*)\z/
|
||||||
value.strip!
|
key, value = Regexp.last_match[1], Regexp.last_match[2]
|
||||||
result[key.to_sym] = value
|
clean_type!(key)
|
||||||
else
|
value.strip!
|
||||||
result[:body] ||= ""
|
result[key.to_sym] = value
|
||||||
result[:body] << l << "\n"
|
else
|
||||||
|
result[:body] ||= ""
|
||||||
|
result[:body] << l << "\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -159,35 +166,36 @@ class Typepad < Thor
|
||||||
when :comment
|
when :comment
|
||||||
comment = parse_comment(value).slice(:author, :email, :url, :body, :date)
|
comment = parse_comment(value).slice(:author, :email, :url, :body, :date)
|
||||||
|
|
||||||
if options[:google_api] && comment[:author] =~ /plus.google.com\/(\d+)/
|
if options[:google_api] && comment[:author] =~ %r{plus.google.com/(\d+)}
|
||||||
gplus_id = Regexp.last_match[1]
|
gplus_id = Regexp.last_match[1]
|
||||||
from_redis = Discourse.redis.get("gplus:#{gplus_id}")
|
from_redis = Discourse.redis.get("gplus:#{gplus_id}")
|
||||||
if from_redis.blank?
|
if from_redis.blank?
|
||||||
json = ::JSON.parse(open("https://www.googleapis.com/plus/v1/people/#{gplus_id}?key=#{options[:google_api]}").read)
|
json =
|
||||||
from_redis = json['displayName']
|
::JSON.parse(
|
||||||
|
open(
|
||||||
|
"https://www.googleapis.com/plus/v1/people/#{gplus_id}?key=#{options[:google_api]}",
|
||||||
|
).read,
|
||||||
|
)
|
||||||
|
from_redis = json["displayName"]
|
||||||
Discourse.redis.set("gplus:#{gplus_id}", from_redis)
|
Discourse.redis.set("gplus:#{gplus_id}", from_redis)
|
||||||
end
|
end
|
||||||
comment[:author] = from_redis
|
comment[:author] = from_redis
|
||||||
end
|
end
|
||||||
|
|
||||||
if comment[:author] =~ /([^\.]+)\.wordpress\.com/
|
comment[:author] = Regexp.last_match[1] if comment[:author] =~ /([^\.]+)\.wordpress\.com/
|
||||||
|
|
||||||
|
comment[:author] = Regexp.last_match[1] if comment[:author] =~ /([^\.]+)\.blogspot\.com/
|
||||||
|
|
||||||
|
if comment[:author] =~ %r{twitter.com/([a-zA-Z0-9]+)}
|
||||||
comment[:author] = Regexp.last_match[1]
|
comment[:author] = Regexp.last_match[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
if comment[:author] =~ /([^\.]+)\.blogspot\.com/
|
if comment[:author] =~ %r{www.facebook.com/profile.php\?id=(\d+)}
|
||||||
comment[:author] = Regexp.last_match[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
if comment[:author] =~ /twitter.com\/([a-zA-Z0-9]+)/
|
|
||||||
comment[:author] = Regexp.last_match[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
if comment[:author] =~ /www.facebook.com\/profile.php\?id=(\d+)/
|
|
||||||
fb_id = Regexp.last_match[1]
|
fb_id = Regexp.last_match[1]
|
||||||
from_redis = Discourse.redis.get("fb:#{fb_id}")
|
from_redis = Discourse.redis.get("fb:#{fb_id}")
|
||||||
if from_redis.blank?
|
if from_redis.blank?
|
||||||
json = ::JSON.parse(open("http://graph.facebook.com/#{fb_id}").read)
|
json = ::JSON.parse(open("http://graph.facebook.com/#{fb_id}").read)
|
||||||
from_redis = json['username']
|
from_redis = json["username"]
|
||||||
Discourse.redis.set("fb:#{fb_id}", from_redis)
|
Discourse.redis.set("fb:#{fb_id}", from_redis)
|
||||||
end
|
end
|
||||||
comment[:author] = from_redis
|
comment[:author] = from_redis
|
||||||
|
@ -195,11 +203,11 @@ class Typepad < Thor
|
||||||
|
|
||||||
comment[:name] = comment[:author]
|
comment[:name] = comment[:author]
|
||||||
if comment[:author]
|
if comment[:author]
|
||||||
comment[:author].gsub!(/\A[_\.]+/, '')
|
comment[:author].gsub!(/\A[_\.]+/, "")
|
||||||
comment[:author].gsub!(/[_\.]+\z/, '')
|
comment[:author].gsub!(/[_\.]+\z/, "")
|
||||||
|
|
||||||
if comment[:author].size < 12
|
if comment[:author].size < 12
|
||||||
comment[:author].gsub!(/ /, '_')
|
comment[:author].gsub!(/ /, "_")
|
||||||
else
|
else
|
||||||
segments = []
|
segments = []
|
||||||
current = ""
|
current = ""
|
||||||
|
@ -225,14 +233,13 @@ class Typepad < Thor
|
||||||
segments << current
|
segments << current
|
||||||
|
|
||||||
comment[:author] = segments[0]
|
comment[:author] = segments[0]
|
||||||
if segments.size > 1 && segments[1][0] =~ /[a-zA-Z]/
|
comment[:author] << segments[1][0] if segments.size > 1 && segments[1][0] =~ /[a-zA-Z]/
|
||||||
comment[:author] << segments[1][0]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
comment[:author] = "commenter" if comment[:author].blank?
|
comment[:author] = "commenter" if comment[:author].blank?
|
||||||
comment[:author] = "codinghorror" if comment[:author] == "Jeff Atwood" || comment[:author] == "JeffAtwood" || comment[:author] == "Jeff_Atwood"
|
comment[:author] = "codinghorror" if comment[:author] == "Jeff Atwood" ||
|
||||||
|
comment[:author] == "JeffAtwood" || comment[:author] == "Jeff_Atwood"
|
||||||
|
|
||||||
comment[:date] = comment[:date] ? DateTime.strptime(comment[:date], "%m/%d/%Y") : Time.now
|
comment[:date] = comment[:date] ? DateTime.strptime(comment[:date], "%m/%d/%Y") : Time.now
|
||||||
entry[:comments] << comment if comment[:body].present?
|
entry[:comments] << comment if comment[:body].present?
|
||||||
|
@ -241,5 +248,4 @@ class Typepad < Thor
|
||||||
|
|
||||||
entry[:title] && entry[:body] ? entry : nil
|
entry[:title] && entry[:body] ? entry : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue