Python Forum
test pattern and add result in a table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
test pattern and add result in a table
#1
Hello,

I need to make a script in order to parse files in a shared folder on windows, making tests of pattern and add results in a table.

In a few words, for each log file, 2 things
if pattern is found -->ok
if pattern is not found --->add error in a table(which will be an html file) with username,email,id of the computer

Here below the script i'm writing

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os.path
import re

data_folder = os.path.join(r"\\shared folder")

file_to_open = os.path.join(data_folder, "*.LOG")

f = open(file_to_open,encoding="utf-8", errors='ignore')

print(f.read())

##controles et actions associes####

## fenetres contextuelles
string = "toto.toto.fr"
regexp = re.findall( r'(^[a-z0-9._-]+@[a-z0-9._-]+\.[(com|fr)]+)')

if re.match(regexp, string) is not None:
print ('TRUE')
else:
print ('FALSE')

etc...

questions

1) how can i write that the script need to parse a shared folder on windows?
2) I've problem with UTF8 and i don't find how to encode it properly?
3) HOW making test pattern and add result in a table (as output)?

Thank you for your help
Reply
#2
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os.path
import re

data_folder = os.path.join(r"\\shared folder\path")

file_to_open = os.path.join(data_folder, "testLOG.txt")

f = open(file_to_open,encoding="utf-8", errors='ignore')

print(f.read())

##controles et actions associes####

## fenetres contextuelles
string = "toto.test.com"
regexp = re.findall( r'(^[a-z0-9._-]+@[a-z0-9._-]+\.[(com|fr)]+)')

if re.match(regexp, string) is not None:
    print ('TRUE')
else:
    print ('FALSE')

print (re.search(regexp, string).groups())

(Mar-05-2019, 02:41 PM)sam1975 Wrote:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os.path
import re

data_folder = os.path.join(r"\\shared folder\path")

file_to_open = os.path.join(data_folder, "testLOG.txt")

f = open(file_to_open,encoding="utf-8", errors='ignore')

print(f.read())

##controles et actions associes####

## fenetres contextuelles
string = "toto.test.com"
regexp = re.findall( r'(^[a-z0-9._-]+@[a-z0-9._-]+\.[(com|fr)]+)')

if re.match(regexp, string) is not None:
    print ('TRUE')
else:
    print ('FALSE')

print (re.search(regexp, string).groups())

questions

1) how can i write that the script need to parse a shared folder on windows?
2) I've problem with UTF8 and i don't find how to encode it properly?
3) HOW making test pattern and add result in a table (as output)?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how do I return Max Test result + corresponding student name from an excel dataset? sean1 3 1,211 Jan-16-2022, 09:07 PM
Last Post: snippsat
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 3,063 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  How to write test cases for a init function by Unit test in python? binhduonggttn 2 3,062 Feb-24-2020, 12:06 PM
Last Post: Larz60+
  How to write test cases by Unit test for database configuration file? binhduonggttn 0 2,511 Feb-18-2020, 08:03 AM
Last Post: binhduonggttn
  code pattern to test if list has all the same Skaperen 5 3,380 Jul-25-2018, 06:09 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020