Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
keyword matching part2
#11
(Dec-21-2018, 07:43 PM)micseydel Wrote: How exactly is it not working?

Explained how exactly it's not working.
Reply
#12
(Dec-28-2018, 03:11 PM)janho Wrote:
(Dec-21-2018, 07:43 PM)micseydel Wrote: How exactly is it not working?

Explained how exactly it's not working.

(Dec-21-2018, 07:43 PM)micseydel Wrote: How exactly is it not working?

i have explained how exactly it's not working now any updates please?
Reply
#13
(Dec-18-2018, 02:01 PM)buran Wrote: What have you tried? We are glad to help, but we are not going to do it for you.

tried below but it's giving wrong line no.
#importing required packages

import glob
from collections import Counter
import re
import xlwt
from xlwt import Workbook
import xlsxwriter 
import xlrd 
import errno
import time
from datetime import datetime
import datetime
import os
import os.path
import warnings
from xlutils.copy import copy
import openpyxl
 
# opening excel file
 
from xlrd import open_workbook
 
warnings.filterwarnings("ignore")
timestr = time.strftime("%Y%m%d-%H%M%S")
 
# path where all the folders and sub folders need to be searched.
 
yourpath = "D:\\mainfolder\\subfolders"
 
 
# location where excel containing all the keywords which are to be searched in above path.
loc = ("D:\\sample.xlsx")
 
cnt = Counter()
wb = xlrd.open_workbook(loc) 
sheet = wb.sheet_by_index(0)
rows = sheet.nrows
 
excel_word=[]
# loop to pick up all the keywords from the column of excel one after another.
 
for i in range(1,rows):
    excel_word.append(sheet.cell_value(i,1))
 
# report to be generated in this location.
report_txt="D:\\mainfolder\\report"+timestr+".txt"
 
# report is opened in write mode.
 
FO = open(report_txt, 'w')
 
# structure layout of text file where records will be written.
 
str3="|"+"Pattern"+" "*(20-len("Pattern"))+"|"+"Vuernabilitiy  in file"+" "*(200-len("Vuernabilitiy  in file"))+"|"+"Line No"+" "*(10-len("Line No"))+"|" +"\n"
FO.write(str3)
FO.write("--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"+"\n")
 
# main logic 
 
for root, dirs, files in os.walk(yourpath, topdown=False):
     
    line=0
    for name in files:
         
        path=os.path.join(root, name)
        files = glob.glob(path)
         
        for name in files:
                 
                 
                try:
                    with open(name,encoding="utf8",errors='ignore') as f:
                         
                        text_string1 = f.read()
                        for i in range(0,len(excel_word)):
                            str2=''
                            for num, line in enumerate(name, 1):
                                if excel_word[i] in text_string1:
                                    cnt[excel_word[i]] += 1
                             
                                    str2="|"+excel_word[i]+" "*(20-len(excel_word[i]))+"|"+os.path.join(root, name)+" "*(200-len(os.path.join(root, name)))+"|"+str(num)+" "*(10-len(str(num)))+"|" +"\n"
                                 
                            else:
                                cnt[excel_word[i]]+=0
                            FO.write(str2)
                             
                             
                                           
                except IOError as exc:
                    if exc.errno != errno.EISDIR:
                        raise
 
FO.close()

Any updates by experts please?

Thanks
Reply
#14
I can't speak for others, but I have not been engaging with your thread because I couldn't make sense out of what you said. You've written a lot here and posted a lot of code, without providing what I would want to in turn provide help.

What is it that I want? I want minimal code that reproduces your issue - usually that's 5-10 lines, not close to 100; do your best to remove anything not relevant. I want a more explicit explanation of what your expected and actual results are, since it's not obvious what "wrong line no" means exactly. I want a full, though minimal, example that reproduces your issue, e.g. an example file structure (even creating a Github repo or uploading a zip somewhere might be appropriate in this case).
Reply
#15
(Dec-31-2018, 05:19 PM)micseydel Wrote: I can't speak for others, but I have not been engaging with your thread because I couldn't make sense out of what you said. You've written a lot here and posted a lot of code, without providing what I would want to in turn provide help.

What is it that I want? I want minimal code that reproduces your issue - usually that's 5-10 lines, not close to 100; do your best to remove anything not relevant. I want a more explicit explanation of what your expected and actual results are, since it's not obvious what "wrong line no" means exactly. I want a full, though minimal, example that reproduces your issue, e.g. an example file structure (even creating a Github repo or uploading a zip somewhere might be appropriate in this case).

How can I upload sample notepad file which is having structure of output report in a text format.this report has line no. column so that after uploading t on this forum you will be able to understand what exactly i mean from wrong line no.
Reply
#16
(Jan-01-2019, 04:58 AM)janho Wrote:
(Dec-31-2018, 05:19 PM)micseydel Wrote: I can't speak for others, but I have not been engaging with your thread because I couldn't make sense out of what you said. You've written a lot here and posted a lot of code, without providing what I would want to in turn provide help.

What is it that I want? I want minimal code that reproduces your issue - usually that's 5-10 lines, not close to 100; do your best to remove anything not relevant. I want a more explicit explanation of what your expected and actual results are, since it's not obvious what "wrong line no" means exactly. I want a full, though minimal, example that reproduces your issue, e.g. an example file structure (even creating a Github repo or uploading a zip somewhere might be appropriate in this case).

How can I upload sample notepad file which is having structure of output report in a text format.this report has line no. column so that after uploading t on this forum you will be able to understand what exactly i mean from wrong line no.
and if you focus on pasted code from line no. 70 to 85 that tries to write line no. in text file report but expectation is that for particular word let's say 'log' when it finds it in some place in disk drive d: in some folder and in some file and when we open this file in notepad++ then the corresponding line number for this searched keyword 'log' must be exactly same which should be written in our text format report using this python script which is pasted here for your reference.
If required can upload text file report which is having incorrect line number for the found keyword in particular file,but i am not sure how to upload that sample report(in text format) here on this forum.

Thanks
Reply
#17
Hi,

This is with respect to previous thread which was not having attachment in it.

previous thread link:-https://python-forum.io/Thread-Keyword-matching

So attaching the report generating incorrect line no. and code for the same please refer previous link where i have pasted the code in this code please focus between line no. 70-85 which is generating incorrect line no.

Thanks

Attached Files

.zip   Line no. report.zip (Size: 13.26 KB / Downloads: 135)
Reply
#18
(Jan-01-2019, 06:55 AM)janho Wrote:
(Jan-01-2019, 04:58 AM)janho Wrote: How can I upload sample notepad file which is having structure of output report in a text format.this report has line no. column so that after uploading t on this forum you will be able to understand what exactly i mean from wrong line no.
and if you focus on pasted code from line no. 70 to 85 that tries to write line no. in text file report but expectation is that for particular word let's say 'log' when it finds it in some place in disk drive d: in some folder and in some file and when we open this file in notepad++ then the corresponding line number for this searched keyword 'log' must be exactly same which should be written in our text format report using this python script which is pasted here for your reference.
If required can upload text file report which is having incorrect line number for the found keyword in particular file,but i am not sure how to upload that sample report(in text format) here on this forum.

Thanks

Hi, I was able to upload sample report in zip file format in other thread on this forum since I was not getting any option to upload it here, so please refer my another link for the same question here it is:-https://python-forum.io/Thread-keyword-matching-part2
Reply
#19
(Jan-01-2019, 12:41 PM)janho Wrote:
(Jan-01-2019, 06:55 AM)janho Wrote: and if you focus on pasted code from line no. 70 to 85 that tries to write line no. in text file report but expectation is that for particular word let's say 'log' when it finds it in some place in disk drive d: in some folder and in some file and when we open this file in notepad++ then the corresponding line number for this searched keyword 'log' must be exactly same which should be written in our text format report using this python script which is pasted here for your reference.
If required can upload text file report which is having incorrect line number for the found keyword in particular file,but i am not sure how to upload that sample report(in text format) here on this forum.

Thanks

Hi, I was able to upload sample report in zip file format in other thread on this forum since I was not getting any option to upload it here, so please refer my another link for the same question here it is:-https://python-forum.io/Thread-keyword-matching-part2
any updates please?
Reply
#20
I merged your threads.

As I said I'm having a very difficult time following you here. Please summarize the current state of things in a minimal manner as I mentioned before (note that minimal inputs are a good idea too, as long as they're representative of the problem).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Find a specific keyword after another keyword and change the output sgtmcc 5 806 Oct-05-2023, 07:41 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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