我需要从2013年1月1日开始,并为每个日期"做一些事情",从而为每个日期生成一个JSON文件.
我已经为一个日期制定了"做一些事情"部分,但是我很难从一个约会开始并循环到另一个结束日期.
我有以下用户控制器:
class UsersController < ApplicationController
def index
@users = User.all
end
def new
@user = User.new
end
def create
@user = User.new(user_params)
@customer = Customer.new
if @user.save
flash.notice = "User '#{@user.email}' was succefully created."
redirect_to user_path(@user)
else
render 'new'
end
end
def show
@user = User.find(params[:id])
end
private
def user_params
params.require(:user).permit(:email, :password, :password_confirmation, customer_attributes: [:id, :company])
end
end
Run Code Online (Sandbox Code Playgroud)
我有以下用户模型:
class User < ActiveRecord::Base
has_one :customer
accepts_nested_attributes_for :customer, :allow_destroy => true
end
Run Code Online (Sandbox Code Playgroud)
以下客户模型:
class Customer < ActiveRecord::Base
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
最后,这是表格: …
我需要指定下个月的第一天.
例如,我希望我的应用说:"您的订单将于2012年2月1日发货",假设我们是在1月份.
有任何想法吗?
我错过了某个地方的设置吗?生成站点时,_posts目录中的markdown文件将自己转换为目录.每个目录中都有一个带有内容的index.html文件.
我显然更喜欢在不为每个帖子创建新目录的情况下生成帖子.
在下面的代码中,我想计算序列中G和C字符的百分比.在Python 3中我得到了正确的结果0.5,但在Python 2中我得到了0.为什么结果不同?
def gc_content(base_seq):
"""Return the percentage of G and C characters in base_seq"""
seq = base_seq.upper()
return (seq.count('G') + seq.count('C')) / len(seq)
gc_content('attacgcg')
Run Code Online (Sandbox Code Playgroud) 到目前为止我有这个:
require 'watir-webdriver'
require 'date'
require 'nokogiri'
browser = Watir::Browser.start 'https://example/ViewReport.aspx'
browser.link(:text, 'Combined Employee Performance Report').click
today = Date.today
yesterday = today.prev_day.strftime('%m' '%d' '%Y')
t = browser.text_field :id => 'UC255_txtStart'
t.set yesterday
t = browser.text_field :id => 'UC255_txtEnd'
t.set yesterday
btn = browser.button :value, 'Run Report'
btn.exists?
btn.click
page = Nokogiri::HTML.parse('browser')
links = page.css("a")
puts links.length
Run Code Online (Sandbox Code Playgroud)
当我尝试解析browserWatir用于站点URI的变量时,它给了我一个空白的HTML页面.
所以,我有一个包含多行和多列的表.
<table>
<tr>
<th>Employee Name</th>
<th>Reg Hours</th>
<th>OT Hours</th>
</tr>
<tr>
<td>Employee 1</td>
<td>10</td>
<td>20</td>
</tr>
<tr>
<td>Employee 2</td>
<td>5</td>
<td>10</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
还有另一张表:
<table>
<tr>
<th>Employee Name</th>
<th>Revenue</th>
</tr>
<td>Employee 2</td>
<td>$10</td>
</tr>
<tr>
<td>Employee 1</td>
<td>$50</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
请注意,员工订单可能在表之间是随机的.
我如何使用nokogiri创建一个以每个员工为对象的json文件,以及他们的总小时数和收入?
目前,我只能使用一些xpath获取单个表格单元格.例如:
puts page.xpath(".//*[@id='UC255_tblSummary']/tbody/tr[2]/td[1]/text()").inner_text
Run Code Online (Sandbox Code Playgroud)
编辑:
使用页面对象gem和来自@Dave_McNulla的链接,我尝试了这段代码只是为了看看我得到了什么:
class MyPage
include PageObject
table(:report, :id => 'UC255_tblSummary')
def get_some_information
report_element[1][2].text
end
end
puts get_some_information
Run Code Online (Sandbox Code Playgroud)
然而,没有任何东西被归还.
数据:https://gist.github.com/anonymous/d8cc0524160d7d03d37b
小时表有一个副本.第一个很好.需要的另一个表是附件收入表.(我还需要激活表,但我会尝试将合并小时和附件收入表的代码合并.
ruby ×3
nokogiri ×2
watir ×2
date ×1
jekyll ×1
json ×1
python ×1
python-2.x ×1
python-3.x ×1
rack ×1
web-scraping ×1