Looking for text in logs - python

I have a new project to develop a log reader in Python 3.5 from txt files and I don't know how to start. The main goal is to extract pieces of logs (substrings) from a large and complex log txt file and display it in a structured way on a webpage. Would be possible please any help with libraries and commands in order to start with? I'm sorry but I'm quite new to Python. Thanks!

I would say you convert the .txt files you mentioned into a list of strings, then use a for-loop:
for a in txt_files:
Then use some if statements to look out for keywords, and print certain messages depending on the input
using this method you could also have it look out for certain words in a certain order, by having "previous_a = a" at the end of each loop

Related

How to create a dynamic form with python using translated text as input?

I have an original text that I want to translate. I normally do it manually but I know I could save a lot of time translating automatically the most frequent words and expressions.
I will find out how to translate simple words, the problem is not here. I have read some books on python and I think using string manipulations can be done.
But I am lost about how to create the output file.
The output file will contain:
short empty forms ready to be filled wherever there is text that has not been translated
the translated words wherever they were in the original file
In the output file I will fill manually the empty forms, after pressing Tab the cursor should jump to the next exmpty form
I am lost here, I know how to do forms on html but the language I am used to is Python.
I would like to know what modules from Python I could use. I need some guidance on this.
Can you recommend me a book or a tool that explains how to do something similar to this?
This is what I want to do, assuming I have managed to create a simple database to translate colors from Spanish to English.
The first step contains the original file.
The second step contains the automatic translation.
In the third step I complete the manual translation.
After finishing everything is grouped into a normal txt file ready to be used.
I think it is quite clear. I don't expect people to tell me the code to do this, I just need to know what tools could be used to achieve my goal.
Thanks for editing.
To create an interface that works with a web browser, Flask for Python is a good method for creating webforms. There are tutorials available.
One method for storing data would be an SQLite file. That may be more than you need, so I'd recommend starting with a CSV file. Libraries exist in Python for both CSVs and SQLite.

table for organizing students registration of subjects

I have to create my own subjects table, I have an excel file which contain subjects groups and dates that are available, I want to create a python program to run over all the combinations of subjects to give me all the available dates of subjects which I want to register in .
actually, I have no idea even how to start,
now I have four subjects let's call them F,N,S and G.
each one has four groups with different times along the week
so I want to generate all the available combinations which there is no overlap between subjects .
all I want is any hint, I don't want the whole solution just any intial thoughts to start.
I'm really a beginner python programmer and I can't think of any thing to launch this project
how to arrange them into matrices????????
Save the excel file as a csv, or "comma-separated values" file. This format is simple plaintext, and easy for programs to use.
In your program, read in the file using open()
Use the csv module to extract the opened file into a list of lists. Each element of the outer list should be another list: [subject, group, date] (or whatever columns are in your table.
Now that you have your information read into the program, look into solutions for the actual algorithm. You can google various scheduling algorithms, but this StackOverflow question gets at what you're looking for, I think, and might serve as a good starting point

Run an autocorrect program on a text file on python

I am very new to Python, and I am currently working on a project. This project would be to create (among other things) a program to correct a text. I am having difficulty combining two separate ideas and parts of code together. First of all, I have been experimenting with a code to correct a word that is inputted by a user.
The code can be found here.
So far, I am using this exact code without any modifications.
My goal is to be able to read a text file and go through it and find and propose corrections for the words which are wrong, as this spellchecker code does.
I would use something like:
with open('words.txt','r') as f:
for line in f:
for word in line.split()
to go through the text file and split it into individual words.
Ideally, if my text said
"Wgat is the definiton" I would want to be able to recognize wgat and correct it to what, and recognize definiton and correct to definition.
How do I combine these two ideas? Thanks
Maybe you should look at this:
https://norvig.com/spell-correct.html
It uses probability to give the best answer without being connected to a database.
Else, you can use urllib to connect to the english dictionary website: http://www.mieliestronk.com/corncob_lowercase.txt
Then find the word that is most closely related to the one inputted and then print the word in this list.
Hope it helps!

Python : Working with text file OR with list

I am currently working on a script to process some log files (few MB). I am quite new to Python and up to now, my method was to extract some information and pass it to another text file and so on. I would then compare different text files and work that way. Even if I would delete the intermediate text files that I used to get my final output, I found it a bit messy.
As I have started to become more acquainted with lists and I am now trying to use lists instead of text files to store and manage data.
I was wondering what is the best method to use. Should I try to use lists more instead of text files or does that not really matter? I would tend to think lists are better for obvious reasons but I wanted to make sure. I hope it is not too much of a silly question. Thanks
EDIT
Quick examples: I would create two text file from the log files and then comparing those text files when now I am doing the same thing with lists
List in python have many methods and features that make it very flexible and manageable.
There are also other types that is similar to lists like generator.
Best of luck.

Python: Scour a folder of files for a specific string, then list all the files containing it

I have a directory of ~100 plaintext files that I wish to search for a pre-defined string via a Python script. All file names of the files in said directory that contain this string will then be output into a CSV text file. How would I approach this best, and what classes would be useful for this?
Have a look at these links.
Python Input Output
Python CSV
Common String Operations
please refer to these two answer of mine, may be this would help you.
multiple search and replace in python
regex search replace in batch

Categories

Resources