Jan 2025【日本東北】溫泉三昧之旅⑤ 在大雪飄落的雪國,追尋秘湯之宿與極上美食(福島~被時光遺忘下的江戶原風景,日本三大茅葺聚落大內宿)

圖片
清晨的陽光穿過窗櫺,灑落在榻榻米上,為房間增添了一抹溫暖的光輝。窗外,白雪皚皚的山脈在晴朗的天空下閃閃發光,預示著美好的一天。我起身走到窗邊,深深吸了一口清新的冬日空氣,心中充滿了對即將到來的一天以及仙峽閣旅館美味早餐的期待。 旅館的餐廳瀰漫著舒適的氛圍。我坐在窗邊的座位上,渴望一邊欣賞迷人的雪景,一邊享用我的早餐。一個擺盤精美的早餐托盤送到了面前,上面擺滿了各種誘人的菜餚。 我的目光首先被一碗晶瑩剔透的白米飯吸引,它的香氣瀰漫在空氣中。旁邊是一份色彩繽紛的沙拉,新鮮的蔬菜搭配玉米粒,令人食慾大增。烤鮭魚散發著陣陣香味,魚皮烤得酥脆可口。溫泉蛋浸泡在清淡的高湯中,看起來既美味又暖胃。 其他幾道小菜也讓這份早餐更加豐富:燉菠菜、裙帶菜炒蒟蒻、山藥泥佐醬油,以及醃梅子和醃黃瓜。最後,一小杯香甜的芒果優格為這頓早餐畫上了完美的句點。 這份早餐不僅美味,而且營養均衡,為我在這個冬季仙境中探索一天提供了滿滿的能量。我細細品味著每一道菜餚,感受著旅館的用心和款待,心中充滿了感激之情,感謝這美好的一天有如此美好的開始。 飯後早晨,我踏出旅館的暖簾,迎接我的是一片銀白色的世界。蘆之牧溫泉街靜靜地沉睡在會津深山的懷抱中,厚厚的積雪覆蓋著屋頂、街道和樹木,彷彿時間也凍結在這一刻。 呼出的氣息在冰冷的空氣中凝結成白霧,我沿著溫泉街漫步,腳步聲在寂靜的早晨顯得格外清晰。偶爾,可以聽見屋簷上融雪滴落的聲音,或是遠處傳來的幾聲鳥鳴,更增添了這份寧靜的氛圍。 阿賀川靜靜地流淌在山谷間,河面上覆蓋著薄薄的冰層,在陽光的照射下閃閃發光。河岸邊的樹木披上了雪白的冬衣,枝椏交錯,形成一道道優美的弧線。溫泉旅館的屋頂冒著裊裊炊煙,為這寒冷的冬日增添了一絲溫暖。 漫步在空無一人的溫泉街上,我彷彿置身於一個與世隔絕的世外桃源。這份寂靜,這份純淨,洗滌了我的心靈,讓我感受到久違的平靜與祥和。 凛冬將群山染成了素雅的銀白,積雪在山坡上鋪陳開來,厚薄錯落,像是誰不經意間揮灑的筆墨,濃淡相宜。裸露的枝枒,在寒風中輕輕搖曳,仿佛在低聲訴說著冬日的故事。遠處的山巒,在霧氣的籠罩下,若隱若現,宛如仙境一般,讓人心生嚮往。 蘆之牧溫泉的冬日,沒有喧囂,沒有繁華,只有那份獨特的靜謐與安詳,像一首悠揚的樂曲,在山谷間輕輕回蕩,令人陶醉其中,忘卻了塵世的煩惱。 這山,這雪,這寧靜的溫泉小鎮,這氤氳的霧氣,交織成一幅絕美的冬日畫卷,...

Extending Ruby on Rails Contacts Gem to invite Facebook friends

Contacts Gem 是一個能夠從Web Mail服務中匯入聯絡人列表的Rails插件,我們可以擴充它來支援匯入Facebook朋友列表,並發送邀請訊息給他們。

首先必須安裝Contacts plugin:
$script/plugin install git://github.com/cardmagic/contacts.git

另外我們還需要安裝Json Gem:
$sudo gem i jason

另外我們還需要安裝Mechanize Gem來使用其相依的Nokogiri:
$sudo gem i mechanize

現在我們可以打開Rails Console來檢查一下:
david@workstation:~/workspace/railscode$ script/console
Loading development environment (Rails 2.2.2)
>> Contacts
=> Contacts
view raw console hosted with ❤ by GitHub

現在到#{RAILS_ROOT}/vendor/plugins/contacts/lib/contacts目錄下建立一個page_scraper.rb:
require 'mechanize'
class Contacts
class PageScraper < Base
attr_accessor :agent
# creates the Mechanize agent used to do the scraping
def create_agent
self.agent = Mechanize.new
agent.keep_alive = false
agent
end
# Logging in
def prepare; end # stub
def strip_html( html )
html.gsub(/<\/?[^>]*>/, '')
end
end
end
view raw page_scraper.rb hosted with ❤ by GitHub

然後在同樣這個目錄下新增facebook.rb:
require 'page_scraper'
class Contacts
class Facebook < PageScraper
URL = "http://www.facebook.com/"
LOGIN_URL = "http://m.facebook.com/"
PROTOCOL_ERROR = "Facebook has changed its protocols, please upgrade this library."
def real_connect
create_agent
prepare
end
def prepare
page = agent.get(LOGIN_URL)
login_form = page.forms.first
login_form.email = @login
login_form.pass = @password
page = agent.submit(login_form, login_form.buttons.first)
raise AuthenticationError, "電郵地址或密碼有錯誤。" if page.body =~ /電郵地址或密碼有誤。/
#Friends Page
friends_links = page.links_with(:href => /\/friends.php/)
friends_link = ''
friends_links.each{ |flink| friends_link = flink.href if flink && flink.href && flink.text == 'Friends'}
raise ConnectionError, PROTOCOL_ERROR unless friends_link
friends_url = 'http://m.facebook.com' + friends_link
page = agent.get(friends_url)
#My Friends Page
friends_link = page.links_with(:href => /\/friends.php/)
@my_friends_link = ''
friends_link.each{|f| @my_friends_link = f.href if f.text == '朋友'}
@logout_url = page.link_with(:href => /logout/)
return true
end
def contacts
contacts = []
next_page = true
current_page = 2
my_friends_url = 'http://m.facebook.com' + @my_friends_link
page = agent.get(my_friends_url)
raise AuthenticationError, "請先登入。" if page.body =~ /輸入帳號和密碼。/
while(next_page)
next_page = false
data = page.search('//tr[@valign="top"]')
if data
data.each do |node|
td_nodes = node.children
if td_nodes
childs = td_nodes[0]
fr_name = childs.child.text
fr_href = ''
childs.children.each do |nd|
if nd.name == 'small'
nd.children.each do |n|
fr_href = n.attributes['href'] if n.name == 'a' && n.text == '訊息'
end
end
end
contacts << [fr_name, fr_href.to_s] unless fr_href.blank?
end
end
end # End Outer if
data = page.search('//div[@class="pad"]')
data.each do |node|
childs = node.children
next if childs.empty?
childs.each do |c|
if c.name == 'a' && c.text.to_i == current_page
next_page = 'http://m.facebook.com' + c.attributes['href'].to_s
break
end
end
end
current_page += 1
page = agent.get(next_page) unless next_page == false
end #End While
return contacts
end
def send_message(contact, message, subj=nil)
success = false
if contact
url_inbox = "http://m.facebook.com" + contact.last
page = agent.get(url_inbox)
raise AuthenticationError, "請先登入。" if page.body =~ /輸入帳號和密碼。/
page.forms.each do |f|
if f.has_field?('body')
f.subject = subj if subj && !subj.empty?
f.body = message
page = agent.submit(f, f.buttons.first)
return true if page.code == '200'
end
end
end
return success
end
def logout
agent.click @logout_url if @logout_url
return true
end
end
TYPES[:facebook] = Facebook
end
view raw facebook.rb hosted with ❤ by GitHub

最後編輯#{RAILS_ROOT}/vendor/plugins/contacts/lib/contact.rb添加下面內容:
require 'facebook'
view raw contacts.rb hosted with ❤ by GitHub

OK!完成了,現在可以打開Rails Console來測試一下:
david@workstation:~/workspace/railscode$ script/console
Loading development environment (Rails 2.2.2)
>> fb=Contacts::Facebook.new('你的facebook帳號','你的密碼')
...
...
>> contacts = fb.contacts
=> [["User1", "/inbox/?compose&ids=xxxxxxxxx&r22287202&refid=5"], ["User2", "/inbox/?compose&ids=xxxxxxxxx&rd297796c&refid=5"], ["User3", "/inbox/?compose&ids=xxxxxxxxx&raf7be31a&refid=5"]]
>> contacts.each{|c|fb.send_message(c, '你要發送的邀請內容', '訊息主旨')}
view raw console hosted with ❤ by GitHub

ps.目前聯絡人列表中,分頁的問題尚待解決!

熱門文章

July 2024【台北士林】陽明山彼端的原始秘境|颱風後的鹿角坑生態保護區|循著疊石指引造訪楓林瀑布

Jan 2025【日本東北】溫泉三昧之旅② 在大雪飄落的雪國,追尋秘湯之宿與極上美食(仙台~品嚐極上米澤牛&奧羽的百年藥湯-鎌先溫泉)

Jan 2025【苗栗三義】富貴牡丹(三義館)人文藝術餐廳|預約制|在美術館裡吃無菜單料理

Jan 2025【日本東北】溫泉三昧之旅⑤ 在大雪飄落的雪國,追尋秘湯之宿與極上美食(福島~被時光遺忘下的江戶原風景,日本三大茅葺聚落大內宿)

Jan 2025【苗栗泰安】泰安警光山莊泡湯&彰化CP值極高的日本料理|沐藏料理所X海龍王|彰化板前料理 ♨️🍁🥢🍲

Feb 2023【台中和平】裡冷林道Off Road單車野營~順登谷關七雄之首八仙山!單車+野營+登山,三個願望一次滿足

日本の登山の歷史

Sep, 2021【苗栗南庄】蓬萊林道Off Road小試|雨後很爛很濕滑|二傳低底盤車勿輕易嘗試

May 2023【雲林古坑】 負離子濃度達都市40倍/漫步木馬古道/順訪雲嶺之丘/山合苑喝咖啡/秋田犬

Mar 2025【桃園楊梅】福人登山步道輕鬆行:探索綠意盎然的自然步道

文章列表

Contact

名稱

以電子郵件傳送 *

訊息 *