Beispiel #1
0
 def output_html(self, user_nick):
     count = 0
     
     dir_name = "image_" + user_nick
     if not os.path.exists(dir_name):
         os.mkdir(dir_name)
     
     for _data in self.datas:
         
         print '正在下载第'+str(count+1)+'张图片,图片地址:'+_data['link']
         
         try:
             pic= requests.get(_data['link'], timeout=10)
         except:
             print '【错误】当前图片无法下载'
             continue
         
         string = dir_name + '/' + _data['fname']
         
         fp = open(string.decode('utf-8').encode('cp936'),'wb')
         fp.write(pic.content)
         fp.close()
     
         count += 1
         
     self.datas = []
Beispiel #2
0
def webhook():
      if request.method == 'POST':
            # channel_access_token = 'xsaSOYmzmLnG6SVtTR4L7cG6IdP+oOVBvbr4EGdQu2F0YGLvckUJK5kQg9DcHsm/fCTdVIYmA9APd/vni6usLJz7cVExWL13tZYEsmJvriaE3r57NREg3TF0eF0UqQv/bmze9BA/e3ZgTv2dzRDC2AdB04t89/1O/w1cDnyilFU='
            data = json.dumps(request.json['events'])
            time = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
            dir_name = 'log_alert_line'

            # Create target Directory if don't exist
            if not os.path.exists(dir_name):
                  os.mkdir(dir_name)
                  print("Directory " , dir_name ,  " Created ")

            for data in json.loads(data):
                  # reply_token = data['replyToken']
                  message = data['message']

            if message['type'] == 'sticker':
                  file = open('{}'.format(dir_name) + '/' + 'log_reply_content' + '.txt', 'a')
                  file.write(time + '  ---  ' + '{}'.format(message) + '\n')
            elif message['type'] == 'text':
                  if message['text'].upper() == 'YES':
                        file = open('{}'.format(dir_name) + '/' + 'log_reply_to_splunk' + '.txt', 'a')
                        file.write(time + '  ---  ' + '{}'.format(message['text']) + '\n')
                  else:
                        file = open('{}'.format(dir_name) + '/' + 'log_reply_content' + '.txt', 'a')
                        file.write(time + '  ---  ' + '{}'.format(message) + '\n')

            file.close()

            return request.json, 200
      elif request.method == 'GET':
            return 200
Beispiel #3
0
def test_typing_not_shown(libspec_manager, tmpdir, workspace, data_regression):
    from robocode_ls_core import uris
    from os.path import os
    from robotframework_ls_tests.fixtures import LIBSPEC_3
    from robotframework_ls.impl import keyword_completions
    from robotframework_ls.impl.completion_context import CompletionContext

    ws_dir = str(tmpdir.join("workspace_dir_a"))
    os.mkdir(ws_dir)
    with open(os.path.join(ws_dir, "my.libspec"), "w") as stream:
        stream.write(LIBSPEC_3)
    libspec_manager.add_workspace_folder(uris.from_fs_path(ws_dir))
    assert libspec_manager.get_library_info("case3_library",
                                            create=False) is not None

    workspace.set_root(str(tmpdir), libspec_manager=libspec_manager)

    doc = workspace.get_doc("temp_doc.robot")
    doc.source = """*** Settings ***
Library    case3_library

*** Test Cases ***
Can use resource keywords
    Case Verify"""

    completions = keyword_completions.complete(
        CompletionContext(doc, workspace=workspace.ws))

    data_regression.check(completions)
Beispiel #4
0
# 关闭打开的文件
fo.close()

fo = open(pathfile, "r+");

strRead = fo.read(30);
print (strRead)

strReada = fo.read();
print (strReada);

fo.close();
#remove()方法删除文件,需要提供要删除的文件名作为参数。
os.remove("foo1.txt");
#rename()方法需要两个参数,当前的文件名和新文件名。
os.renames("foo.txt", "foo1.txt");

#可以使用os模块的mkdir()方法在当前目录下创建新的目录们。你需要提供一个包含了要创建的目录名称的参数
os.mkdir("test");
#可以用chdir()方法来改变当前的目录。chdir()方法需要的一个参数是你想设成当前目录的目录名称。
os.chdir("test")
#getcwd()方法显示当前的工作目录。
# 给出当前的目录
print  (os.getcwd());


#os.removedirs("")


def test_libspec_manager_caches(libspec_manager, tmpdir):
    from robotframework_ls import uris
    from os.path import os
    from robotframework_ls_tests.fixtures import LIBSPEC_1
    from robotframework_ls_tests.fixtures import wait_for_condition
    from robotframework_ls_tests.fixtures import LIBSPEC_2
    from robotframework_ls_tests.fixtures import LIBSPEC_2_A
    import time

    ws_dir = str(tmpdir.join("workspace_dir_a"))
    os.mkdir(ws_dir)
    with open(os.path.join(ws_dir, "my.libspec"), "w") as stream:
        stream.write(LIBSPEC_1)
    libspec_manager.add_workspace_folder(uris.from_fs_path(ws_dir))
    assert libspec_manager.get_library_info("case1_library",
                                            create=False) is not None

    libspec_manager.remove_workspace_folder(uris.from_fs_path(ws_dir))
    library_info = libspec_manager.get_library_info("case1_library",
                                                    create=False)
    if library_info is not None:
        raise AssertionError("Expected: %s to be None after removing %s" %
                             (library_info, uris.from_fs_path(ws_dir)))

    libspec_manager.add_workspace_folder(uris.from_fs_path(ws_dir))
    assert libspec_manager.get_library_info("case1_library",
                                            create=False) is not None

    # Give a timeout so that the next write will have at least 1 second
    # difference (1s is the minimum for poll to work).
    time.sleep(1.1)
    with open(os.path.join(ws_dir, "my2.libspec"), "w") as stream:
        stream.write(LIBSPEC_2)

    def check_spec_found():
        library_info = libspec_manager.get_library_info("case2_library",
                                                        create=False)
        return library_info is not None

    # Updating is done in a thread.
    wait_for_condition(check_spec_found, sleep=1 / 5.0)

    library_info = libspec_manager.get_library_info("case2_library",
                                                    create=False)
    assert set(x.name for x in library_info.keywords) == set(
        ["Case 2 Verify Another Model", "Case 2 Verify Model"])

    # Give a timeout so that the next write will have at least 1 second
    # difference (1s is the minimum for poll to work).
    time.sleep(1)
    with open(os.path.join(ws_dir, "my2.libspec"), "w") as stream:
        stream.write(LIBSPEC_2_A)

    def check_spec_2_a():
        library_info = libspec_manager.get_library_info("case2_library",
                                                        create=False)
        if library_info:
            return set(x.name for x in library_info.keywords) == set(
                ["Case 2 A Verify Another Model", "Case 2 A Verify Model"])

    # Updating is done in a thread.
    wait_for_condition(check_spec_2_a, sleep=1 / 5.0)
    writer = pd.ExcelWriter(filePath)
    dataFrame.to_excel(writer, sheet_name=sheetName, index=False)
    writer.save()


if __name__ == '__main__':

    # list of connection strings
    connStrings = {'dbalias':'un/[email protected]:1521/servicename'}

    dt = datetime.datetime.now().strftime('%Y%m%d%H%M')

    exportDate = datetime.datetime.today().strftime('%Y%m%d_%H%M')

    # Export folder and file
    exportFolder = r'.\SQL_Exports'

    if not (os.path.exists(exportFolder)):
        os.mkdir(exportFolder)

    exportFilePath = os.path.join(exportFolder, 'sqlexport_' + exportDate + '.xlsx')
    exportFilePath_merged = os.path.join(exportFolder, 'sqlexport_' + exportDate + '_merged.xlsx')

    for dbalias, connectionString in connStrings.items():
        print(dbalias + " " + connectionString)
        df = read_from_db(connectionString)
        write_to_xlsx(df, exportFilePath,dbalias)

    mergeExcelSheets(exportFilePath, exportFilePath_merged)

Beispiel #7
0
# Open a File
file = open(file="text.txt", mode='wb', buffering=1)
print("Name of the title: ", file.name)
print("Closed or not: ", file.closed)
print("Opening mode: ", file.mode)
file.write(
    bytes("I am not a psychopath, I am a high functioning sociopath.\n",
          "UTF-8"))
file.close()

file = open(file="text.txt", mode="r", buffering=1)
print("Position: ",
      file.tell())  # Tell the position of the current seeking point.
data = file.read()  # Read all bytes
file.close()
print("The read data is: ", data)
print("Closed or not: ", file.closed)

# Use the OS path library.
os.rename("text.txt", "newText.txt")  # Rename the file name.
os.remove("newText.txt")  # Remove the file with this file name.
os.mkdir("folder", mode=0o777)
os.chdir("folder")
# Changes the current directory with this.
os.mkdir("test")  # Makes folder in folder with name test.

print("The current dir: ", os.getcwd())  # Prints the current directory path.
os.rmdir("folder")
# Removes the directory.