This is a better alternative because it has control key and arrow keys
Tuesday, June 19, 2012
taking a screenshot htc one v of ssh session of vpsville
hold the power button for 2 seconds and press the home key to take a screen shot
you will need to remove the lower back cover to install the microsd card
all filea are stored in this dcim locatoon
you will need to remove the lower back cover to install the microsd card
all filea are stored in this dcim locatoon
Tuesday, June 12, 2012
Basic Ubuntu Linux Commands for VPSVille
ls -l
the above command list the directory with added information
date
the above command shows the date
cat filename
list the contents of user supply filename
cat filename | more
list the file contents 1 screen at a time, press space to move to the next screen
rm filename
delete the file
ps ax
shows running process
top
like taskmanager on windows, type quit to quit
the above command list the directory with added information
date
the above command shows the date
cat filename
list the contents of user supply filename
cat filename | more
list the file contents 1 screen at a time, press space to move to the next screen
rm filename
delete the file
ps ax
shows running process
top
like taskmanager on windows, type quit to quit
Python read file splitlines alternatives
Due to the low memory conditions of a VPS, I found this better.
#create an array
file1TextArray=[]
file1 = open('/root/file1new.txt', 'r')
for line in file1:
file1TextArray.append(line[:-2])
file1.close()
Tested on Python3
Note this deletes the last two characters because the text file had \r\n as the new line delimeter
#create an array
file1TextArray=[]
file1 = open('/root/file1new.txt', 'r')
for line in file1:
file1TextArray.append(line[:-2])
file1.close()
Tested on Python3
Note this deletes the last two characters because the text file had \r\n as the new line delimeter
Monday, June 11, 2012
Day 3 on VPSVille nohup working!
root@x:~# ps ax
PID TTY STAT TIME COMMAND
1 ? Ss 0:02 init
3809 ? S 0:00 /usr/sbin/apache2 -k start
5916 ? Ss 0:00 SCREEN
5917 pts/1 Ss+ 0:00 /bin/bash
6130 ? S 0:00 /usr/sbin/apache2 -k start
7786 ? Rs 0:00 sshd: root@pts/0
7926 pts/0 Ss 0:00 -bash
13696 pts/3 R 4233:08 python vpsville-nohup.py
14242 pts/2 Ss+ 0:00 /bin/bash
15492 pts/3 Ss+ 0:00 /bin/bash
20411 ? Ssl 0:00 /usr/sbin/named -u bind
22133 pts/0 R+ 0:00 ps ax
23905 ? Ss 0:00 cron
23960 ? Ss 0:03 /sbin/syslogd -u syslog
24023 ? Ss 0:02 /usr/sbin/sshd -D
24217 ? S 0:00 /usr/sbin/apache2 -k start
24342 ? S 0:00 /usr/sbin/apache2 -k start
24476 ? S 0:00 /usr/sbin/apache2 -k start
29810 ? Ss 0:00 sendmail: MTA: accepting connections
29958 ? Ss 0:00 /usr/sbin/apache2 -k start
30191 ? Ss 0:00 /usr/sbin/xinetd -dontfork -pidfile /var/run/xinetd.pid -staya
root@x:~#
As you can see from the time, it's been up for a lot of minutes, almost 2.9 days
Friday, June 8, 2012
Killing a NoHup Python process in Ubuntu Linux hosted on VPSVille utilizing TOP and PS AX
- Okay, need to logout.
- Logging out kills the process.
- Use nohup python3 scriptfile.py &
- Yes ampersand at end
- use ls-l to list files with sizes to see if working
- kill process, issue command TOP
- from top, type k
- then type the process id should be a number
- Watch out for Memory Error
- ps ax list the process id also
- need to issue: kill -s SIGKILL PROCESSID
WPut on dynadot
Wput
apt-get install wput
wput readword.sqlite ftp://www.rope-string-strip-lighting.info:PASSWORDHERE@webhost.dynadot.com/readword.sqlite
Wednesday, June 6, 2012
Setting up Python on VPSVille
I tried pythonanywhere, but kept restarting service. So signed up for a VPS. Need putty, filezilla Setup FTP http://madppc.com/setting-up-your-ubuntu-810-vps-with-vps-ville-pt-2-ftp-users-mail/ --------------- https://secure.vpsville.ca/login email: password: one originally given note after multiple restarts Reinstall OS Template wait for email and new password "Virtual Server Ready" install putty or use SSH TERMINAL go to ip indicated in email 76.74.137.28 open connection default settings ok username: root password: email apt-get install nano apt-get update apt-get upgrade reboot apt-get install python3.2 addgroup admin adduser username adduser username admin nano /etc/sudoers exit login ftp apt-get -y install vsftpd nano /etc/vsftpd.conf anonymous_enable=NO #local_enable=YES #write_enable=YES /etc/init.d/vsftpd restart might replace with service vsftpd restart must login via puttty as username = root apt-get install python3.2
Thursday, May 24, 2012
Select from SQLite Database using Python return records that start with a Character
import re
import sqlite3
#----------------setup database
conn = sqlite3.connect('h:\\Python\\ReadWord\\readword.sqlite')
c = conn.cursor()
# Do this instead
#t = (symbol,)
c.execute('''SELECT * FROM uniquephrase WHERE match_text_sum LIKE "a%" ''')
for row in c:
waitForInput = input('--> ')
print(row)
# Save (commit) the changes
#conn.commit()
# Close db before too many connections
c.close()
Friday, May 18, 2012
Compare Words in Two Files All Matches and Store in an Sqlite Database using Python
import re
import sqlite3
COMMONWORDS=['the',
'be',
'to',
'of',
'and',
'a',
'in',
'that',
'have',
'I',
'it',
'for',
'not',
'on',
'with',
'he',
'as',
'you',
'do',
'at',
'this',
'but',
'his',
'by',
'from',
'they',
'we',
'say',
'her',
'she',
'or',
'an',
'will',
'my',
'one',
'all',
'would',
'there',
'their',
'what',
'so',
'up',
'out',
'if',
'about',
'who',
'get',
'which',
'go',
'me',
'when',
'make',
'can',
'like',
'time',
'no',
'just',
'him',
'know',
'take',
'person',
'into',
'year',
'your',
'good',
'some',
'could',
'them',
'see',
'other',
'than',
'then',
'now',
'look',
'only',
'come',
'its',
'over',
'think',
'also',
'back',
'after',
'use',
'two',
'how',
'our',
'work',
'first',
'well',
'way',
'even',
'new',
'want',
'because',
'any',
'these',
'give',
'day',
'most',
'us']
#----------------setup database
conn = sqlite3.connect('h:\\Python\\ReadWord\\readword.sqlite')
#for pythonanywhere
#conn = sqlite3.connect('/home/torontoomar/readword3.sqlite')
c = conn.cursor()
# Create table matchtext
c.execute('''DROP TABLE IF EXISTS matchtext''')
c.execute('''create table matchtext(ID INTEGER PRIMARY KEY, match_text text, length_text real,
file1_position real, file2_position real,
file1_pad text, file2_pad text, match_text_sum text, length_sum_text real, uniquephraseID INTEGER)''')
# Create table unique_phrase
c.execute('''DROP TABLE IF EXISTS uniquephrase''')
c.execute('''create table uniquephrase(ID INTEGER PRIMARY KEY, match_text_sum text, length_sum_text real, numtimes real)''')
# Save (commit) the changes
conn.commit()
#----------------end setup database
def checkIfInDatabase(match_text_sum,length_sum_text ):
tuple_to_select = (match_text_sum,)
c.execute('''select * from uniquephrase where match_text_sum=?''', tuple_to_select )
#need to fetchone since can't rely on c.rowcount
cursorRow = c.fetchone()
lastrowid=1
if cursorRow is not None:
cursorRowId=cursorRow[0]
lastrowid=cursorRowId
print('id:',cursorRowId)
cursorNumTimes = cursorRow[3]
print('numTimes:',cursorNumTimes)
cursorNumTimes +=1
tuple_to_update = (cursorNumTimes, cursorRowId)
print(cursorRowId)
c.execute('''update uniquephrase set numtimes=? where ID=?''', tuple_to_update )
conn.commit()
else:
tuple_to_insert =(match_text_sum,length_sum_text,1)
c.execute('''insert into uniquephrase(match_text_sum, length_sum_text, numtimes) values (?,?,?)''', tuple_to_insert)
conn.commit()
#only works for insert statement lastrowid
lastrowid=c.lastrowid
return lastrowid
def addToDatabase(match_text, length_text, file1_position,file2_position, file1_pad, file2_pad, diagonalArray):
# go through common words an only pick ones that don't exist
# if all removed, then special case?
newDiagonalArray=[]
for matchWord in diagonalArray:
uniqueWord=True
for commonWord in COMMONWORDS:
if matchWord == commonWord:
uniqueWord=False
if uniqueWord==True:
newDiagonalArray.append(matchWord)
length_sum_text=len(newDiagonalArray)
match_text_sum =" ".join(newDiagonalArray)
#check if in database, if not add as a unique item
lastrowid=checkIfInDatabase(match_text_sum, length_sum_text)
# id is auto increment if omit, but must name columns
tuple_to_insert = (match_text, length_text, file1_position,file2_position, file1_pad, file2_pad,match_text_sum, length_sum_text,lastrowid)
c.execute('''insert into matchtext(match_text, length_text,
file1_position, file2_position,file1_pad,
file2_pad, match_text_sum, length_sum_text, uniquephraseID) values (?,?,?,?,?,?,?,?,?)''', tuple_to_insert)
conn.commit()
#for pythonanywhere
#file1 = open('/home/torontoomar/file1.txt', 'r')
file1 = open('h:\\Python\\ReadFile\\file1.txt', 'r')
file1Text = file1.read()
file1.close()
#for pythonanywhere
#file2 = open('/home/torontoomar/file2.txt', 'r')
file2 = open('h:\\Python\\ReadFile\\file2.txt', 'r')
file2Text = file2.read()
file2.close()
file1Text=file1Text.lower()
file2Text=file2Text.lower()
file1List=file1Text.splitlines()
file2List=file2Text.splitlines()
file1Text=" ".join(file1List)
file2Text=" ".join(file2List)
#clean up file1Text and file2Text , and .
file1TextArray = re.findall(r"\w+", file1Text)
file2TextArray = re.findall(r"\w+",file2Text)
len_file1=len(file1TextArray)
len_file2=len(file2TextArray)
diagonal_size=(len_file1+len_file2)-1
currentDiagonalArray=[]
MAX_DIAGONAL_SIZE=3
PAD_SPACE=30
currentDiagonalLen=0
maxrow=len_file2
maxcol=len_file1
print("1,1----------------------------")
#----------------------------------
#do case 1,1
if maxrow==maxcol:
total_range=maxrow
elif maxrow > maxcol:
total_range=maxcol
elif maxrow < maxcol:
total_range=maxrow
file1_index=0
file2_index=0
for i in range(total_range):
#while (1):
file1Word = file1TextArray[file1_index]
file2Word = file2TextArray[file2_index]
#print(file1_index,":",file2_index)
#print(file1Word," ",file2Word)
#-----add to database-------
if file1Word==file2Word:
#http://wiki.python.org/moin/PythonSpeed/PerformanceTips
currentDiagonalArray.append(file1Word)
else:
if len(currentDiagonalArray) > MAX_DIAGONAL_SIZE:
currentDiagonalStr=" ".join(currentDiagonalArray)
print(len(currentDiagonalStr),currentDiagonalStr," : ", file1_index , " , ", file2_index)
#---------------------------------------------------------
padFile1Before=file1_index-PAD_SPACE
padFile1After=file1_index+PAD_SPACE
padFile2Before=file2_index-PAD_SPACE
padFile2After=file2_index+PAD_SPACE
quote_file1Array=file1TextArray[padFile1Before:padFile1After]
quote_file2Array=file2TextArray[padFile2Before:padFile2After]
quote_file1Str=" ".join(quote_file1Array)
quote_file2Str=" ".join(quote_file2Array)
print("q: ",quote_file1Str)
print("b: ",quote_file2Str)
print("---------------------------------")
#insert into database and commit
match_text=currentDiagonalStr
length_text=len(currentDiagonalStr)
file1_position=file1_index
file2_position=file2_index
file1_pad=quote_file1Str
file2_pad=quote_file2Str
addToDatabase(match_text, length_text, file1_position,file2_position, file1_pad, file2_pad, currentDiagonalArray)
#---------------------------------------
currentDiagonalArray=[]
currentDiagonalLen=0
#-----end add to database------
#increment downwards
file1_index+=1
file2_index+=1
# C---------------------------
##need to clean up
## DUMP
print("above----------------------------")
#----------------------------------
# do case minrow,column from 2 to maxrow
# startend = (maxcol-varcol) + 1, maxcolumn
# above the line
currentDiagonalArray=[]
currentDiagonalLen=0
file1_index=1
file2_index=0
prev_file1_index=1
counter=0
#for i in range(total_range):
while (1):
counter+=1
file1Word = file1TextArray[file1_index]
file2Word = file2TextArray[file2_index]
#print(file1_index,":",file2_index)
#print(file1Word," ",file2Word)
#-----add to database-------
if file1Word==file2Word:
currentDiagonalArray.append(file1Word)
else:
if len(currentDiagonalArray) > MAX_DIAGONAL_SIZE:
currentDiagonalStr=" ".join(currentDiagonalArray)
print(len(currentDiagonalStr),currentDiagonalStr," : ", file1_index , " , ", file2_index)
#---------------------------------------------------------
padFile1Before=file1_index-PAD_SPACE
padFile1After=file1_index+PAD_SPACE
padFile2Before=file2_index-PAD_SPACE
padFile2After=file2_index+PAD_SPACE
quote_file1Array=file1TextArray[padFile1Before:padFile1After]
quote_file2Array=file2TextArray[padFile2Before:padFile2After]
quote_file1Str=" ".join(quote_file1Array)
quote_file2Str=" ".join(quote_file2Array)
print("q: ",quote_file1Str)
print("b: ",quote_file2Str)
print("---------------------------------")
#insert into database and commit
match_text=currentDiagonalStr
length_text=len(currentDiagonalStr)
file1_position=file1_index
file2_position=file2_index
file1_pad=quote_file1Str
file2_pad=quote_file2Str
addToDatabase(match_text, length_text, file1_position,file2_position, file1_pad, file2_pad, currentDiagonalArray)
#---------------------------------------
currentDiagonalArray=[]
currentDiagonalLen=0
#-----end add to database------
#increment downwards
file1_index+=1
file2_index+=1
if file2_index > (maxrow-1) or file1_index > (maxcol-1):
currentDiagonalArray=[]
#print(maxrow, "greater file2_index than maxrow-1", file2_index)
file2_index=0
prev_file1_index+=1
file1_index=prev_file1_index
if file1_index > (maxcol-1):
#print("MAXIMUM above")
break
print("counter",counter,"range",total_range)
#print("below----------------------------")
#----------------------------------
# below the line
currentDiagonalArray=[]
currentDiagonalLen=0
file1_index=0
file2_index=1
total_range = ((maxrow-1) * maxcol) - 1
prev_file2_index=1
counter=0
#for i in range(total_range):
while(1):
counter+=1
file1Word = file1TextArray[file1_index]
file2Word = file2TextArray[file2_index]
#print(file1_index,":",file2_index)
#print(file1Word," ",file2Word)
#-----add to database-------
if file1Word==file2Word:
currentDiagonalArray.append(file1Word)
currentDiagonalLen+=1
else:
if len(currentDiagonalArray) > MAX_DIAGONAL_SIZE:
currentDiagonalStr=" ".join(currentDiagonalArray)
print(len(currentDiagonalStr),currentDiagonalStr," : ", file1_index , " , ", file2_index)
#---------------------------------------------------------
padFile1Before=file1_index-PAD_SPACE
padFile1After=file1_index+PAD_SPACE
padFile2Before=file2_index-PAD_SPACE
padFile2After=file2_index+PAD_SPACE
quote_file1Array=file1TextArray[padFile1Before:padFile1After]
quote_file2Array=file2TextArray[padFile2Before:padFile2After]
quote_file1Str=" ".join(quote_file1Array)
quote_file2Str=" ".join(quote_file2Array)
print("q: ",quote_file1Str)
print("b: ",quote_file2Str)
print("---------------------------------")
#insert into database and commit
match_text=currentDiagonalStr
length_text=len(currentDiagonalStr)
file1_position=file1_index
file2_position=file2_index
file1_pad=quote_file1Str
file2_pad=quote_file2Str
addToDatabase(match_text, length_text, file1_position,file2_position, file1_pad, file2_pad, currentDiagonalArray)
#---------------------------------------
currentDiagonalArray=[]
currentDiagonalLen=0
#-----end add to database------
if(counter % 100000000 == 0):
print(total_range/counter)
#increment downwards
file1_index+=1
file2_index+=1
if file2_index > (maxrow-1) or file1_index > (maxcol-1):
currentDiagonalArray=[]
currentDiagonalLen=0
#print(maxrow, "greater file2_index than maxrow-1", file2_index)
file1_index=0
prev_file2_index+=1
file2_index=prev_file2_index
if file2_index > (maxrow-1):
#print("MAXIMUM below")
break
# Close db before too many connections
c.close()
waitForInput = input('--> ')
print(waitForInput)
Saturday, March 24, 2012
Installing Packages for Python 2.7
Just type
python setup.py install
python must be in your path
Go to DOS
type SET PATH=%PATH%;c:\Python27
must have install keyword or will get error
python setup.py install
python must be in your path
Go to DOS
type SET PATH=%PATH%;c:\Python27
must have install keyword or will get error
How to download PIP for Python 3 under Windows 8
distribute_setup.py
Right click and save the above target
Then click the search button for windows.
Type CMD
to open up a shell.
add python to path
SET PATH=%PATH%;c:\Python32
then CD over to where you saved distribute_setup
execute it
python distribute_setup.py
Now download pip, extract it using 7Zip
http://www.pip-installer.org/en/latest/installing.html
type
python get-pip.py
If you don't do these steps in order you might get an error about setuptools module not installed.
Now you need to add the scripts folder of python where easy_install and now pip resides
Back to the command prompt
set PATH=%PATH%;c:\Python32\Scripts
Now you can install all 20000 packages on
http://pypi.python.org/pypi
So in your DOS shell, type pip install [packagename]
EXAMPLE
C:\Users\Omar\Desktop>pip install pyatom
Downloading/unpacking pyatom
Real name of requirement pyatom is pyatom
Downloading pyatom-1.2.tar.gz
Running setup.py egg_info for package pyatom
Installing collected packages: pyatom
Running setup.py install for pyatom
File "c:\Python32\Lib\site-packages\pyatom.py", line 61
return u'<%s type="xhtml"><div xmlns="%s">%s</div></%s>\n' % \
^
SyntaxError: invalid syntax
Successfully installed pyatom
Cleaning up...
C:\Users\Omar\Desktop>
MODULES is another name for PACKAGES
make sure no script has the same name as your package
so you can't name your script pyatom or you will get an error
Python: Idle: ImportError: cannot import name pyatom
Right click and save the above target
Then click the search button for windows.
Type CMD
to open up a shell.
add python to path
SET PATH=%PATH%;c:\Python32
then CD over to where you saved distribute_setup
execute it
python distribute_setup.py
Now download pip, extract it using 7Zip
http://www.pip-installer.org/en/latest/installing.html
type
python get-pip.py
If you don't do these steps in order you might get an error about setuptools module not installed.
Now you need to add the scripts folder of python where easy_install and now pip resides
Back to the command prompt
set PATH=%PATH%;c:\Python32\Scripts
Now you can install all 20000 packages on
http://pypi.python.org/pypi
So in your DOS shell, type pip install [packagename]
EXAMPLE
C:\Users\Omar\Desktop>pip install pyatom
Downloading/unpacking pyatom
Real name of requirement pyatom is pyatom
Downloading pyatom-1.2.tar.gz
Running setup.py egg_info for package pyatom
Installing collected packages: pyatom
Running setup.py install for pyatom
File "c:\Python32\Lib\site-packages\pyatom.py", line 61
return u'<%s type="xhtml"><div xmlns="%s">%s</div></%s>\n' % \
^
SyntaxError: invalid syntax
Successfully installed pyatom
Cleaning up...
C:\Users\Omar\Desktop>
MODULES is another name for PACKAGES
make sure no script has the same name as your package
so you can't name your script pyatom or you will get an error
Python: Idle: ImportError: cannot import name pyatom
Python read file directory and output all files to a csv list
import os
import re
import csv
os.chdir('c:\\Users\\Omar\\Output')
filesList=os.listdir()
#https://sites.google.com/site/aboutbiblequran/home/samewords
dirFile=open('directoryListing.csv', 'w', newline='')
csvWriter = csv.writer(dirFile)
for filePath in filesList:
csvWriter.writerow([filePath])
dirFile.close()
Sunday, March 18, 2012
Read Quran Text file Compare it with Bible and Remove Common Words
import re
wordListPattern=re.compile('[a-z]+',re.IGNORECASE)
#------------------------------------------
# quran
#------------------------------------------
quranFile=open("C:\\Users\\Omar\\Desktop\\QuranEnglishUS\\superquran.txt")
quranLines=quranFile.readlines()
quranFile.close()
lineNumber=0
numberOfLine=len(quranLines)
quranWordList=[]
for line in quranLines:
line=line.lower()
lineList=wordListPattern.findall(line)
quranWordList.extend(lineList)
lineNumber=lineNumber+1
#print(lineNumber,":",numberOfLine)
#print(lineNumber, ":" ,lineList)
print('end quran dump')
quranWordSet=set(quranWordList)
#------------------------------------------
# bible
#------------------------------------------
bibleFile=open("C:\\Users\\Omar\\Desktop\\webtxt\\superbible.txt")
bibleLines=bibleFile.readlines()
bibleFile.close()
lineNumber=0
numberOfLine=len(bibleLines)
bibleWordList=[]
for line in bibleLines:
line=line.lower()
lineList=wordListPattern.findall(line)
bibleWordList.extend(lineList)
lineNumber=lineNumber+1
#print("Bible ",lineNumber,":",numberOfLine)
print('end bible dump')
bibleWordSet=set(bibleWordList)
#------------------------------------------
# common word list
#------------------------------------------
commonFile=open("C:\\Users\\Omar\\Desktop\\commonword1000.txt")
commonLines=commonFile.readlines()
commonFile.close()
lineNumber=0
numberOfLine=len(commonLines)
commonWordList=[]
for line in commonLines:
line=line.lower()
lineList=wordListPattern.findall(line)
commonWordList.extend(lineList)
lineNumber=lineNumber+1
print('end common dump')
commonWordSet=set(commonWordList)
intersectionWordSet = quranWordSet.intersection(bibleWordSet)
differenceWordSet = intersectionWordSet.difference(commonWordSet)
sortedWordSet= sorted(differenceWordSet)
#print(sorted(intersectionWordSet))
print('---cleaned----')
#print())
for s in sortedWordSet:
print (s)
Saturday, March 17, 2012
Compare to CSV files to see if the rows match.
I needed this for an excel sheet in which I sorted one.
I wanted to double check that I didn't mess up anything when sorting.
I wanted to double check that I didn't mess up anything when sorting.
import csv
origfile=open("C:\\Users\Omar\Desktop\pythonOriginal.csv")
dialect=csv.Sniffer().sniff(origfile.read(1024))
origfile.seek(0)
countorig=0
reader=csv.reader(origfile,dialect)
origlist=[]
for row in reader:
countorig=countorig+1
origlist.append('|'.join(row))
countcomp=0
complist=[]
compfile=open("C:\\Users\Omar\Desktop\pythonCustom.csv")
readercomp=csv.reader(compfile,dialect)
for row in readercomp:
countcomp=countcomp+1
complist.append('|'.join(row))
print (countcomp, " ", countorig )
counti=0
for i in origlist:
counti=counti+1
countFound=False
for j in complist:
if i==j:
countFound=True
break
if countFound==False:
print("Not Found",counti," ",i)
else:
print("Found",counti)
Subscribe to:
Comments (Atom)
