我的最终目标是将当前日期和时间与 ISO8601 格式的 TVMaze API 返回的日期和时间进行比较,以确定是否已播出新的电视节目。
use strict;
use warnings;
use feature 'say';
use DateTime;
my $curmytime = DateTime->now()->format_cldr("yyyy-MM-dd'T'HH:mm:ssZ");
# Output is: Time now in UTC:2017-07-17T10:44:52+0000
say "Time now in UTC:". $curmytime;
my $strtobeparsed = '2017-04-09T21:00:00-0400';
# Next, parse the string "2017-04-09T21:00:00-0400" to a DateTime object
Run Code Online (Sandbox Code Playgroud)
如何将字符串解析为 DateTime 对象?
我刚刚开始使用字符和数组.我写了一些代码来生成一些随机和非随机字符串.好吧,实际上它应该为Dominos pizza生成廉价代码.咳咳...
无论如何,这是代码,我对任何输出都没有感到困惑.我用gcc -Wall编译,没有警告或错误.所以很明显,这是关于字符串的一些基本结构方面.
我很感激有关这方面的任何见解.
码:
#include <stdio.h>
#include <stdlib.h>
#include "conio.h"
#include <time.h>
int genrandom(int,int);
char randAlph(void);
char letterize(int);
char randDigit(void);
char digitize(int);
void weaver(void);
void prtall(char[],int);
int main (void) {
srand(time(0));
weaver();
return 0;
}
void weaver(void) {
//BG5C?---1
char word[10];
word[0]='B';
word[1]='G';
word[2]='5';
word[3]='C';
word[4]=randDigit();
word[5]=randAlph();
word[6]=randAlph();
word[7]=randAlph();
word[8]='\0';
prtall(word,8);
}
void prtall(char worder[],int len){
int i;
for (i=0;(i=len);i++) {
if ( worder[i] != '\0' ){
printf("%c",worder[i]);
}
}
printf("\n");
}
int genrandom(int mino,int maxo) {
int …Run Code Online (Sandbox Code Playgroud) 我是Javascript的新手,并试图更好地理解它.我有一个由PHP生成的表单,使用POST中的数据.表单有一些隐藏的表单字段,应该在验证后填充值.
相关的HTML代码:
<form action="" method="post" name="FormProcessor">
<b>Domain Name: </b>
<input type="text" name="MAIN_DOMAINNAME" value="" id="DomainField">
<input type="hidden" name="CONF_FILE" value="" id="ConfFile">
<div id="infomsg">
Run Code Online (Sandbox Code Playgroud)
Javascript代码:
$(document).ready (function()
{
$('#DomainField').blur(function() {
var DomField=$("#DomainField");
var DomText=DomField.val();
var fold="/var/lib/bind/db.";
alert(fold+DomText);
var ConfFile=$("#ConfFile");
ConfFile.val(fold+DomText);
ConfFile.show();
});
});
Run Code Online (Sandbox Code Playgroud)
<input>当前一个字段的焦点丢失时,我试图让第二个字段变为"未被隐藏".该函数被执行,并显示警报.
在检查来源时,我可以看到它显示:
<input type="hidden" id="ConfFile" value="/var/lib/bind/db.g.com" name="CONF_FILE" style="display: inline;">
Run Code Online (Sandbox Code Playgroud)
所以这个值是传播的,所以我确实正确地解决了这个问题.为什么它不显示?
我的代码几乎取自模块cpan页面:
use strict;
use warnings;
use LWP::Curl;
my $lwpcurl = LWP::Curl->new();
my $referer = 'http://www.example.com/';
my $post_url = 'https://example';
my $key='363073020844984X3v2';
my $hash='73wKwB802h8y26VrmyGD4TIqXSnsV7u39DDOOCd82578t9c92paeBABnMH0ahzp6lzH';
my $action='boot'; # ACTION="info&ipaddr=true&mem=true&hdd=true&bw=true"
my $hash_form = {
'KEY' => $key,
'HASH' => $hash,
'action' => $action,
}
my $content = $lwpcurl->post($post_url, $hash_form, $referer);
print $content;
Run Code Online (Sandbox Code Playgroud)
我得到一个奇怪的语法错误:
syntax error at soluscontrol.pl line 16, near "my "
Global symbol "$content" requires explicit package name at /root/bash-advanced-scripts/soluscontrol.pl line 16.
Global symbol "$hash_form" requires explicit package name at /root/bash-advanced-scripts/soluscontrol.pl line …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
my $str = 'Uploaded 07-02?05:14, Size 212.14?MiB, ULed by someone';
print "Pre:".$str."\n";
my $str =~ s/^[a-zA-z0-9,]//g;
print "Post:".$str."\n";
Run Code Online (Sandbox Code Playgroud)
我的目的是删除那些特殊的字符和空格,以便我可以拆分字符串进行进一步处理.
使用上面的正则表达式,我试图删除除字母数字字符和逗号之外的所有字符.不幸的是,我得到一个空白.我是正则表达式的初学者,想知道我的表达方式有什么问题.
我正在尝试学习在php中使用mysql.我开始试图在mysql中创建一个表,并使用mysqli扩展.
我的代码:
<?php
$truemsg = "Table created successfully";
$falsemsg = "Error creating table: ";
$servername = "localhost";
$username = "myuser";
$password = "mypass";
$db = "mytable";
// Create database
$sql = "USE ".$db.";".
'CREATE TABLE IF NOT EXISTS Authentication (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
userid VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,
role VARCHAR(20) NOT NULL,
email VARCHAR(50)
);';
print "Sql command is ".$sql;
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) …Run Code Online (Sandbox Code Playgroud) 我已经能够使用简单的HTML结构从网站上抓取数据,并使用Perl模块Web :: Scraper从各种标签中检索数据.但是,我遇到了一个data-我无法以通常的方式处理的属性.
标签是:
<img class="slide_image"
src="https://image.slidesharecdn.com/computerassistedsurgery-160629113952/95/computer-assisted-surgery-1-638.jpg?cb=1467200461"
data-small="https://image.slidesharecdn.com/computerassistedsurgery-160629113952/85/computer-assisted-surgery-1-320.jpg?cb=1467200461"
data-normal="https://image.slidesharecdn.com/computerassistedsurgery-160629113952/95/computer-assisted-surgery-1-638.jpg?cb=1467200461"
data-full="https://image.slidesharecdn.com/computerassistedsurgery-160629113952/95/computer-assisted-surgery-1-1024.jpg?cb=1467200461"
alt="COMPUTER ASSISTED SURGERY Something ">
Run Code Online (Sandbox Code Playgroud)
我需要的部分是"https://image.slidesharecdn.com/computerassistedsurgery-160629113952/95/computer-assisted-surgery-1-1024.jpg?cb=1467200461"在属性之后data-full.我目前的代码是:
use strict;
use warnings;
use lib "lib";
use URI;
use Web::Scraper;
use YAML;
use WWW::Mechanize;
use URI::Encode;
use HTTP::Cookies;
use LWP::UserAgent;
use Data::Dumper;
my $purlToScrape='https://www.slideshare.net/drdeepashivnani/computer-assisted-surgery?from_m_app=android';
print "Scraping $purlToScrape\n";
my $noticescr = scraper {
process 'section>img', 'link[]' => 'TEXT';
};
my $notices = $noticescr->scrape(URI->new($purlToScrape));
print Dumper($notices);
Run Code Online (Sandbox Code Playgroud)
这失败并出现错误:
不知道如何处理0 => undef at /usr/local/share/perl/5.20.2/Web/Scraper.pm第150行.
我怎样才能解决这个问题?
我的代码中包含以下段.该块实际上是一个调试块,用于在使脚本生效之前进行检查.
if ($_COOKIE['visits'] = '' )
{
$dbgmsg="No cookie found";
$visits=1;
setcookie('visits',$visits,time() + (86400*30)); // 86400 = 1 day 900=15mins
}
else
{
$visits=$_COOKIE['visits'];
//$dbgmsg="Cookie found. Value is".$_COOKIE['visits'];
$dbgmsg='<p>Cookie found. Value is'.$_COOKIE["visits"].'</p>';
$visits++;
setcookie('visits',$visits,time() + (86400*30));
}
Run Code Online (Sandbox Code Playgroud)
脚本运行时,输出为: Cookie found. Value is
意味着不显示cookie的值.检查Chrome中的Cookie值会显示Cookie"访问"存在,值为1.但代码似乎进入了else块.但检索到的值是null?
我希望根据访问量增加cookie的值.
我有以下代码:
my $xmlrpc = XML::RPC->new('http://api.opensubtitles.org/xml-rpc');
my $result = $xmlrpc->call('SearchSubtitles', $token, @args);
&lp ("Number of subtitle files found:".keys $result->{data});
my $count=0;
mkdir "./Subs";
foreach my $key ( keys $result->{data} )
{
Run Code Online (Sandbox Code Playgroud)
编译失败并显示错误:
Type of argument to keys on reference must be unblessed hashref or arrayref at /root/subtitlegetter/getsubs.pl line 210.
在包含该keys语句的两行上.
$ result看起来像这样:
$result = {
'seconds' => '0.014',
'status' => '200 OK',
'data' => [
{
'SubFeatured' => '0',
'SubHearingImpaired' => '0',
'SubAuthorComment' => undef,
'SubDownloadLink' => 'http://dl.opensubtitles.org/en/download/filead/src-api/vrf-cc714a2b91/1951829762.gz',
'MovieNameEng' …Run Code Online (Sandbox Code Playgroud) 我的perl代码如下所示:
my $ns = scraper {
process "table.table tr>td>a", 'files[]' => 'TEXT';
};
my $mres = $ns->scrape(URI->new($purlToScrape));
if ( ($#{$mres->{files}}) > 0 ) {
print Dumper($mres->{files} );
foreach my $key (keys %{ $mres->{files} }) {
print @{$mres->{files}}[$key]."\n";
}
}
Run Code Online (Sandbox Code Playgroud)
在跑步的时候:
$VAR1 = [
'Metropolis (1927)',
'The Adventures of Robin Hood (1938)',
'King Kong (1933)',
'The Treasure of the Sierra Madre (1948)',
'Up (2009)',
'Lawrence of Arabia (1962)',
];
Not a HASH reference at /root/bash-advanced-scripts/rotten.pl line 28.
Run Code Online (Sandbox Code Playgroud)
第28行是这样的:
print @{$mres->{files}}[$key]."\n";
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
场景:我需要将多个电视节目的名称传递给脚本:例如。 ./script -a "Homeworld" -a "Supernatural"
我正在使用 Getopt::Long::Configure 来获取选项。
sub ArgParser
{
my ($help,$addshow,$delshow,$checkshow,$listshows) = ();
GetOptions ('help|h' => \$help,
'add|a=s' => \$addshow,
);
if ($help)
{
HelpPrint;
}
elsif ($addshow)
{
say $addshow;
}
else
{
HelpPrint("Invalid option or no options specified!");
}
exit;
}
ArgParser;
Run Code Online (Sandbox Code Playgroud)
目前,脚本只接收最后一个指定的参数。如何检测是否在命令行上传递了同一个参数的多个参数?
@ARGV 确实包含所有参数,那么我该如何使用它们呢?
我正在尝试使用 django 使用boxsdk将文件上传到box.com,同时将应用程序部署到heroku。问题是我的代码在本地开发服务器上运行良好,但在heroku 上运行不佳。如果应用程序在本地运行,它也可以工作heroku local web
对于本地开发服务器,我可以导入 json 文件进行身份验证。对于heroku,由于它不接受conf 文件,因此我使用heroku:config 将文件存储为环境变量。
from boxsdk import JWTAuth, Client
from io import StringIO
import os
jsonpath = f'{STATIC_ROOT}/conf/box.json'
try:
auth = JWTAuth.from_settings_file(jsonpath)
except:
BOXCONF = os.environ.get('BOXCONF')
msg = f'The value of BOXCONF is {BOXCONF}'
capture_message(msg)
auth = JWTAuth.from_settings_file(StringIO.new(BOXCONF))
client = Client(auth)
service_account = client.user().get()
print('Service Account user ID is {0}'.format(service_account.id))
Run Code Online (Sandbox Code Playgroud)
我已经使用 Sentry 的 capture_message 测试了 BOXCONF 的设置,它显示以下内容:
The value of BOXCONF is {
"boxAppSettings": {
"clientID": "abcd",
"clientSecret": "abc",
"appAuth": {
"publicKeyID": …Run Code Online (Sandbox Code Playgroud) 在我的models.py中,我有:
def MakeOTP():
import random,string
return ''.join(random.choices(string.digits, k=4))
class Prescriptionshare(models.Model):
prid = models.AutoField(primary_key=True, unique=True)
customer = models.ForeignKey(
customer, on_delete=models.CASCADE, null=True)
time = models.DateTimeField(default=timezone.now)
checkin =models.ForeignKey(Checkins, on_delete=models.CASCADE, null=True)
otp = models.CharField(max_length=5, default=MakeOTP())
Run Code Online (Sandbox Code Playgroud)
在我的django shell中,我尝试了以下内容:
pq = Prescriptionshare(customer = cus, checkin = chk)
pq.save()
Run Code Online (Sandbox Code Playgroud)
问题是,每次执行此操作时,我都会在otp字段中获得相同的字符串.字符串没有随机变化.为什么会这样?