Jump to content
cmiN

Keyword finder v1.0 [cmiN]

Recommended Posts

Un mic tool care citeste fisiere .txt .xml .doc etc (sa fie bazate pe text) care contin chei si cuvinte (de exemplu usere si parole) separate prin ":" unele de altele. Dupa ce le citeste poti afla ce cuvant apartine cheii dorite sau ce cheie apartine cuvantului respectiv. E facut mai mult pentru gui ca de abia invat sa fac interfete in python si e un fel de beta pentru ca vreau sa-l optimizez si sa-i fac cat mai multe optiuni / tipuri de separatoare / A.I. etc. Astept pareri si propuneri:

Nu l-am facut executabil pentru ca nu a aparut py2exe inca pentru versiunea 3.0

download Python 3.0

http://pastebin.com/f6ac7d998

#! /usr/bin/env python3.0
# -*- coding: cp1252 -*-
# by cmiN for sharky

from tkinter import *
from tkinter import filedialog
from tkinter import messagebox

def frames():
global root
root=Tk()
frame=Frame(root)
menu=Menu(root)
root.config(menu=menu)
filemenu=Menu(menu)
menu.add_cascade(label='File', menu=filemenu)
filemenu.add_command(label='Open', command=open_list)
filemenu.add_separator()
filemenu.add_command(label='Exit', command=bye)
helpmenu=Menu(menu)
menu.add_cascade(label='Help', menu=helpmenu)
helpmenu.add_command(label='About...', command=msgbox1)

def bye():
root.destroy()

def create_widgets():
global content1, content2, text1, ext2, message3
message1=Label(text='Key/Word: ')
message1.pack(side='top',anchor='n')
content1=StringVar()
content1.set('Enter your string...')
text1=Entry(fg='grey', bg='white', textvariable=content1)
text1.pack(side='top',fill='x')
text1.bind('<Button-1>', clear_text)
text1.bind('<Key>', clear_text)
message2=Label(text='Key/Word: ')
message2.pack()
content2=StringVar()
content2.set('')
text2=Entry(fg='red', bg='grey', textvariable=content2)
text2.pack(fill='x')
text2.bind('<Key>', clear_text)
button2=Button(text='Search', command=search)
button2.pack()
message3=Label(text='Status: Waiting')
message3.pack(side='bottom', anchor='sw')
button1=Button(text='Exit', bg='cyan', fg='red', command=bye)
button1.pack(side='bottom', anchor='se')

def clear_text(event):
text1['fg']='black'
if content1.get()=='Enter your string...':
content1.set('')

def open_list():
try:
global txt_list, txt
ftypes=[('Text Documents', '*.txt'), ('Word Documents', '*.doc'), ('XML Files', '*.xml')]
txt_list=filedialog.askopenfile(parent=root, mode='r', title='Chose a .txt file', filetypes=ftypes)
txt=txt_list.readlines()
except:
messagebox.showerror('File Error', 'Failed to open file')

def msgbox1():
messagebox.showinfo('About', 'Keyword finder v1.0\n\
\n\
This program will open a text based file and find the word for a key or the key for that word\n\
\n\
Usage: Click File -> Open -> select a file -> input some text -> click search\n\
Supported separators: " : "\n\
Ex: something:1154aad24b\n\
\n\
\n\
Copyright © 2009. All rights reserved. "cmiN"')

def search():
message3['text']='Status: Searching... (please wait)'
try:
statement=False
for kw in txt:
nr=kw.index(':')
if content1.get()==kw[:nr]:
if kw[-1]=='\n':
content2.set(kw[1+nr:-1])
else:
content2.set(kw[1+nr:])
statement=True
elif content1.get()==kw[1+nr:] or content1.get()+'\n'==kw[1+nr:]:
content2.set(kw[:nr])
statement=True
else:
pass
if not statement is True:
content2.set(' Nothing finded... ')
except:
message3['text']='Status: Error -> Invalid file or list! (please read About)'
content2.set(" Can't find... ")
else:
message3['text']='Status: The operation completed successfully!'

def end():
root.title('Keyword finder')
root.minsize(330,200)
root.maxsize(600,200)
root.mainloop()

frames()
create_widgets()
end()

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...