我想编写连接到我的大学SFTP服务器的脚本,并通过练习下载最新的文件.到目前为止,我已经改变了Paramiko示例中的代码,但我不知道如何下载最新文件.
这是我的代码:
import functools
import paramiko
class AllowAnythingPolicy(paramiko.MissingHostKeyPolicy):
def missing_host_key(self, client, hostname, key):
return
adress = 'adress'
username = 'username'
password = 'password'
client = paramiko.SSHClient()
client.set_missing_host_key_policy(AllowAnythingPolicy())
client.connect(adress, username= username, password=password)
def my_callback(filename, bytes_so_far, bytes_total):
print ('Transfer of %r is in progress' % filename)
sftp = client.open_sftp()
sftp.chdir('/directory/to/file')
for filename in sorted(sftp.listdir()):
if filename.startswith('Temat'):
callback_for_filename = functools.partial(my_callback, filename)
sftp.get(filename, filename, callback=callback_for_filename)
client.close()
Run Code Online (Sandbox Code Playgroud) 我有一个我试图在这里运行的powerset实现:http://rextester.com/runcode .我仍然遇到这个错误,无法弄清楚如何使它正确.我试图尽可能多地阅读有关哈希尔的IO,但这对我来说太难了.
import Control.Monad (filterM)
powerset = filterM (const [True, False])
main = powerset[1,2]
Run Code Online (Sandbox Code Playgroud) Haskell IO系统对我来说是超级难以理解所以我有疑问:如何从标准输入读取到列表?我知道有函数getLine :: IO String和交互.但我不知道如何将输入转换为列表,所以我可以在这三个函数中使用它:
powerset [] = [[]]
powerset (x:xs) = xss ++ map (x:) xss
where xss = powerset xs
main = print $ powerset([1,2])
import Control.Monad(filterM)
p = filterM(const[True,False])
main = p[1,2]
main = subsequences([1,2])
Run Code Online (Sandbox Code Playgroud)
我希望能够写入1 2 3并将此值传递给函数.你能说/怎么做?
额外的问题
Haskell充满了魔力,所以我想知道是否有可能直接在函数中使用输入,如下所示:
main = subsequences(some input magic here)
Run Code Online (Sandbox Code Playgroud) 如果它在 html 标签中,我需要编写与单词不匹配的正则表达式。
这是文本示例:
asdd qwe <a href="http://example.com" title="Some title with word qwe" class="external-link" rel="nofollow"> qwe
Run Code Online (Sandbox Code Playgroud)
我的正则表达式现在看起来像这样:
(?!(\<.+))[^a-zA-Z?????ó????????Ó???](<class="bad-word"(?: style="[^"]+")?>)?(qwe)(<>)?[^a-zA-Z?????ó????????Ó???](?!.+\>)
Run Code Online (Sandbox Code Playgroud)
这有点复杂,但everythink 的工作期望当我在 regex101.com 和 regexr.com 上测试它时,它只匹配 html 标签之后的单词。
知道为什么吗?
编辑:
我不想使用 html 解析器或 DOM 操作,我不想更改这么多代码。
def test_tagged_word_present(self):
input = 'words <a href="example.com" title="title with word qwe" class="external-link" rel="nofollow"> qwe some other words'
expected = 'words <a href="example.com" title="title with word qwe" class="external-link" rel="nofollow"><strong class="bad-word" style="color:red">qwe</strong> some other words'
parser = self.get_test_parser(input, search_word='qwe')
text = parser.mark_words()
self.assertEqual(text, expected)
Run Code Online (Sandbox Code Playgroud)
一切正常,除了正则表达式仍然缓存qwe在标题中。