[Tutor] Resource question?

2012-08-14 Thread Scurvy Scott
Hello, I'm totally new to this list.

I've been learning python through codecademy.com which has een helping a
lot with it's step by step approach. I'm wondering if there are any others
like it? I've been looking at some other places that attempt to teach
python (google python course, code kata or some such thing, and a couple of
others) but I just have an easier time learning with that step by step
approach. was wondering if anyone knew of anything even remotely similar.

Thanks in advance.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Lambda?? Whaaaaat?

2012-08-30 Thread Scurvy Scott
I'm fairly new to python having recently completed LPTHW. While randomly 
reading stack overflow I've run into "lambda" but haven't seen an explanation 
of what that is, how it works, etc.
Would anyone care to point me in the right direction?

Thanks in advance

Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] List all possible 10digit number

2012-08-31 Thread Scurvy Scott
First of all thank you guys for all your help. The manual is really no 
substitute for having things explained in laymans terms as opposed to a 
technical manual.

My question is this- I've been trying for a month to generate a list of all 
possible 10 digit numbers. I've googled, looked on stackoverflow, experimented 
with itertools, lists, etc to no avail. The closest I've gotten is using 
itertools to generate every possible arrangement of a list

List = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

I feel like I'm close but can't quite get it. Any suggestions or shoves in the 
right direction would be helpful. An issue I've encountered is that python 
won't do something like

For I in range(10, 99):
Print I

Without crashing or throwing an exception.

I've also tried to do something like

I in range (100, 900):
   Etc
And then concatenate the results but also to no avail.

Again, any shoves in the right direction would be greatly appreciated.

Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] All possible 16 character alphanumeric strings?

2012-09-15 Thread Scurvy Scott
Hello again python tutor list.
I have what I see as a somewhat complicated problem which I have no idea
where to begin. I'm hoping you fine folks can help me.

I'm trying to generate a list of every possible 16 character string
containing only 2-7 and a-z lowercase. I've seen some examples using regex
to define which characters I want to use but not a way to generate the
complete list of all possibilities. I'm not looking for a handout- just a
point in the right direction.

Any information would be awesome, thanks.

Right now I've got something like:

import random
>>> ''.join(random.choice('234567abcdefghijklmnopqrstuvwxyz') for i in 
>>> range(16))

Which only prints 1 number, obviously.

or possibly something like this:


def genKey():
hash = hashlib.md5(RANDOM_NUMBER).digest().encode("base32")
alnum_hash = re.sub(r'[^a-z2-7]', "", hash)
return alnum_hash[:16]


Keeping in mind that although I understand this code, I did not write it, I
got it from stackoverflow.

Again any help would be great. Feel free to ask if you must know exactly
what I'm trying to do.

I'm running Ubuntu 12.04 and python 2.7

Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] All possible 16 character alphanumeric strings?

2012-09-15 Thread Scurvy Scott
>
> That list would fill all the PC's on the planet a few billions times.
> The number of items in the list has 25 digits in it.  print 32**16
>
> I actually should've specified that the list I'm trying to create would
not start at say "0001".
I'm attempting to generate all possible .onion addressess which look like "
kpvz7ki2v5agwt35.onion" for instance.


The TOR network generates these numbers with this method:
"If you decide to run a hidden service Tor generates an
RSA-1024keypair. The .onion name is
computed as follows: first the
 SHA1  hash of the
DER-encoded
 ASN.1  public
key is calculated. Afterwards the first half of the hash is encoded to
Base32  and the suffix ".onion" is
added. Therefore .onion names can only contain the digits 2-7 and the
letters a-z and are exactly 16 characters long."
-from the Tor Hidden Services DOC page.

I'm not sure if that changes anything as far as the impossible size of my
dataset.

Again, any input is useful.

Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] All possible 16 character alphanumeric strings?

2012-09-15 Thread Scurvy Scott
possible = "234567abcdefghijklmnopqrstuvwxyz"
word_length = 16
print 'Running "every.py"'
word_list = []
def add_word(word):
if len(word)==word_length:
word_list.append(word)
print word
else:
for c in possible:
new_word = word + c
add_word(new_word)


The only problem with this code is that it actually takes a word as its
input and just checks that it is == word length. If not it just appends the
string possible to the variable word that was called in the function
add_word.

I need to be able to generate every possible combination of the characters
in the variable possible, ideally coming up with a string that resembles
the TOR hidden network strings that look like this: "kpvz7ki2v5agwt35.onion"


Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to run this block of code dozens of times

2012-09-16 Thread Scurvy Scott
Hello all, I'm just wondering how to run this block of code X amount of
times (a lot) and then store the ouput to a .txt file.

The code I've written is below.

from Crypto.PublicKey import RSA
import hashlib
m = RSA.generate(1024)
b = hashlib.sha1()
b.update(str(m))
a = b.hexdigest()
print a[:16] + '.onion'


Thanks in advance
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to run this block of code dozens of times

2012-09-16 Thread Scurvy Scott
scratch that, new code is below for your perusal:

from Crypto.PublicKey import RSA
import hashlib

def repeat_a_lot():
count = 0
while count < 20:
m = RSA.generate(1024)
b = hashlib.sha1()
b.update(str(m))
a = b.hexdigest()
print a[:16] + '.onion'
count += 1
repeat_a_lot()


Thanks again, Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to run this block of code dozens of times

2012-09-16 Thread Scurvy Scott
On Sun, Sep 16, 2012 at 5:23 PM, Dave Angel  wrote:

> On 09/16/2012 07:56 PM, Scurvy Scott wrote:
> > scratch that, new code is below for your perusal:
> >
> > from Crypto.PublicKey import RSA
> > import hashlib
> >
> > def repeat_a_lot():
> > count = 0
> > while count < 20:
>
> >You're kidding, aren't you?  while loops are meant for those times when
> >you don't know how many times the loop is to iterate.
>
>
Acutally, Dave, I would be the one setting just how many times the loop
would run manually. Actually the loop would run 2^80 times, so it was more
of a test to see if the output was different each time it ran more than
trying to run it the correct amount of times.


> > m = RSA.generate(1024)
> > b = hashlib.sha1()
> > b.update(str(m))
> > a = b.hexdigest()
> > print a[:16] + '.onion'
> > count += 1
> > repeat_a_lot()
> >
> >
> >
>
> def repeat_a_lot():
> for _ in xrange(20):
> m = RSA.generate(1024)
> b = hashlib.sha1()
> b.update(str(m))
> a = b.hexdigest()
> print a[:16] + '.onion'
>
> repeat_a_lot()
>
>

Why would you use an underscore rather than a letter or name like I've
always seen. I've never seen an underscore used before.

Scott

>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to run this block of code dozens of times

2012-09-16 Thread Scurvy Scott
Wow, thanks Dave, et al., for explaining things the way they did. I'm not
trying to and apologize for top posting, gmail wasn't giving me the option
of replying to all.  I definitely understand what was going on and why when
you all were explaining the code portions to me.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question regarding lists and manipulating items in lists.

2013-01-15 Thread Scurvy Scott
Hello guys, I'm using Ubuntu 12.10 and Python 2.7 right now. I'm working on
code using the Mingus module but this question isn't specific to this
module, per se.

What I'm trying to do is to generate the fibonacci numbers up to a given N
and then do modulo 12 on each number in order to create a list of numbers
for the Mingus module to convert to notes. What I would like to do is store
each note created in a different element in a list so that I can later
manipulate it, say by removing certain note letters from the list at will.
That way the scales created by the program can become more useful, for
example I could remove all notes that aren't present in say a Harmonic
Minor scale, and only keep the list items that do exist in that scale in a
given key. That way it becomes, in a way, like the computer is writing your
guitar solos! Pretty neat I think.

Anyways, the problem I'm having is I'm not really sure how to search a list
for multiple elements and remove just those elements. Below is my code so
far, and information y'all could provide would be appreciated. Thanks.

import mingus.core.notes as notes
#fibonacci
def fib(num1,num2):
a, b = 0, 1
for i in xrange(num1,num2):
c = b % 12 #modulo 12 on each generated fibonacci number
a_list= [notes.int_to_note(c)] #using Mingus to translate the Fib mod12
numbers into notes and then (I think) storing each one as an element in a
list?
a, b = b, a+b #this is just the algorithm for the fibonacci numbers
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question regarding lists and manipulating items in lists.

2013-01-15 Thread Scurvy Scott
On Tue, Jan 15, 2013 at 4:01 PM, Steven D'Aprano  wrote:
> On 16/01/13 10:40, Scurvy Scott wrote:
> [...]
>
>> Anyways, the problem I'm having is I'm not really sure how to search a
>> list
>> for multiple elements and remove just those elements. Below is my code so
>> far, and information y'all could provide would be appreciated. Thanks.
>
>
> Actually, your problem so far is that you aren't even producing a list of
> elements at all, you keep creating a *single* element, then throwing it
> away when you generate the next Fibonacci number.
>
> Also, you, or more likely Gmail, lost the indentation in your code, so I'm
> going to have to guess what you intended rather than what you have. That's
> because you are sending HTML email, which eats spaces.
>
>
>
>> import mingus.core.notes as notes
>> #fibonacci
>> def fib(num1,num2):
>> a, b = 0, 1
>> for i in xrange(num1,num2):
>> c = b % 12 #modulo 12 on each generated fibonacci number
>> a_list= [notes.int_to_note(c)] #using Mingus to translate the Fib mod12
>> numbers into notes and then (I think) storing each one as an element in a
>> list?
>> a, b = b, a+b #this is just the algorithm for the fibonacci numbers
>
>
>
> Firstly, I recommend that you follow the principle "separation of concerns".
> Keep a separate function for each part of the problem:
>
> * generate Fibonacci numbers;
> * turn them into notes;
>
>
> So here I extract out of your code (untested!) a generator which produces
> an infinite series of Fibonacci numbers, one at a time:
>
> def fib():
>
> a, b = 0, 1
> while True:
> yield b
>
> a, b = b, a+b
>
>
> This is untested, I may have got it wrong.
>
> Next, a function to generate notes from those Fibonacci numbers:
>
>
> def make_notes(num_notes):
> it = fib()
> notes = []  # start with an empty list
> for i in range(num_notes):
> n = next(it) % 12  # get the next Fibonacci number, modulo 12
> notes.append(notes.int_to_note(n))
> return notes
>
>
> That returns a list of notes.
>
>
> Does that help? Start with that, and see how you go.
>
>
>
> --
> Steven
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Steve
After playing with your example I keep being told that list has no
attribute int_to_note. I know what the problem is, I just don't know
how to fix it.
Also, I believe I've fixed my email so it will no longer be in HTML or
anything fancy, just plain text.

So right now my code is:

import mingus.core.notes as notes


#fibonacci
def fib():
a, b = 0, 1
while True:
yield b
a, b = b, a+b


def make_notes(num_notes):
it = fib()
notes = []
for i in range(num_notes):
n = next(it) % 12
notes.append(notes.int_to_note(n))
return notes

Which is pretty different from what my original code was. The
generator function doesn't actually do anything when called, it just
tells me it's a generator function and where it's located. And like I
said the listing function doesn't want to comply with the module being
called under append method. My code was working almost as I intended
it to, it just wasn't creating a list properly of everything, which I
didn't notice until after one of you guys mentioned it to me. Now I
see it and I can sorta visualize what I'm supposed to do, but can't
see what to do to fix it, if that makes any sense.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question regarding lists and manipulating items in lists.

2013-01-15 Thread Scurvy Scott

>> So here I extract out of your code (untested!) a generator which produces
>> an infinite series of Fibonacci numbers, one at a time:
>>
>> def fib():
>>
>> a, b = 0, 1
>> while True:
>> yield b
>>
>> a, b = b, a+b
>>
>>
>> This is untested, I may have got it wrong.
>>
>> Next, a function to generate notes from those Fibonacci numbers:
>>
>>
>> def make_notes(num_notes):
>> it = fib()
>> notes = []  # start with an empty list
>> for i in range(num_notes):
>> n = next(it) % 12  # get the next Fibonacci number, modulo 12
>> notes.append(notes.int_to_note(n))
>> return notes
>>
>>
>> That returns a list of notes.
>>
>>
>> Does that help? Start with that, and see how you go.
>>
>>
>>
>> --
>> Steven
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
> Steve
> After playing with your example I keep being told that list has no
> attribute int_to_note. I know what the problem is, I just don't know
> how to fix it.
> Also, I believe I've fixed my email so it will no longer be in HTML or
> anything fancy, just plain text.
>
> So right now my code is:
>
> import mingus.core.notes as notes
>
>
> #fibonacci
> def fib():
> a, b = 0, 1
> while True:
> yield b
> a, b = b, a+b
>
>
> def make_notes(num_notes):
> it = fib()
> notes = []
> for i in range(num_notes):
> n = next(it) % 12
> notes.append(notes.int_to_note(n))
> return notes
>
> Which is pretty different from what my original code was. The
> generator function doesn't actually do anything when called, it just
> tells me it's a generator function and where it's located. And like I
> said the listing function doesn't want to comply with the module being
> called under append method. My code was working almost as I intended
> it to, it just wasn't creating a list properly of everything, which I
> didn't notice until after one of you guys mentioned it to me. Now I
> see it and I can sorta visualize what I'm supposed to do, but can't
> see what to do to fix it, if that makes any sense.


On a hunch I've gone back to my original code, and feel I've almost
got the list properly working.

import mingus.core.notes as notes


#fibonacci
def fib(num1,num2):
a, b = 0, 1
for i in xrange(num1,num2):
c = b % 12
a_list= []
a, b = b, a+b
while True:
a_list.append(notes.int_to_note(c))
print a_list

The problem here, which most of you will probably see immediately, is
that all this does is infinitely append the same note to the list over
and over again, which is not my intention. This is the closest I've
gotten the code to actually working somewhat correctly as far as this
list is concerned. Any hints would be helpful.

I also think Oscars solution with searching the list for items in the
'search' list and then just removing them is the most elegant so far
but I'm still open to anything you guys can show me, that's why you're
the tutors and I came here to ask, right?

I appreciate any information y'all can share.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question regarding lists and manipulating items in lists.

2013-01-19 Thread Scurvy Scott
[SNIP]

Thank you guys so much, sorry for the delayed response. It's awesome
being able to learn a thing or two from people who know so much about
their craft. I've got the code working the way I envisioned it now and
probably couldn't without y'alls help.

I'm so glad this mailing list exists, thanks again.

Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Scurvy Scott
Hey all how're things?

I'm hoping for some guidance on a problem I'm trying to work through.
I know this has been previously covered on this list but I'm hoping it
won't bother you guys to run through it again.

My basic program I'm attempting to create is like this..

I want to read from a large, very large file.
I want to find a certain string
if it finds the string I would like to select the first 15-20
characters pre and proceeding the string and then output that new
string to a new file along with the line the string was located on
within the file.

It seems fairly straight forward but I'm wondering if y'all can point
me to a direction that would help me accomplish this..

Firstly I know I can read a file and search for the string with (a
portion of this code was found on stackoverflow and is not mine and
some of it is my own)

with open('largeFile', 'r') as inF:
for line in inF:
myString = "The String"
if 'myString' in line:
f = open(thenewfile', 'w')
f.write(myString)
f.close()

I guess what I'm looking for then is tips on A)My stated goal of also
writing the 15-20 characters before and after myString to the new file
and
B)finding the line number and writing that to the file as well.

Any information you can give me or pointers would be awesome, thanks in advance.

I'm on Ubuntu 12.10 running LXDE and working with Python 2.7

Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Scurvy Scott
>
> Why not just use grep ?
>
Honestly this seemed like a good excuse to write some code and learn
some stuff, secondly, it honestly just didn't dawn on me.

Also, the code y'all both showed me was exactly what I was looking for
and I'm planning on using Nicks code as a template to improve upon.

As always, thank you guys a lot, it usually only takes a couple of
emails from y'all to get my brain working correctly.

Be safe,
Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Scurvy Scott
One last question on this topic..

I'd like to call the files and the string form the command line like

Python whatever.py STRINGTOSEARCH NEWFILE FILETOOPEN

My understanding is that it would be accomplished as such

import sys

myString = sys.argv[1]
filetoopen = sys.argv[2]
newfile = sys.argv[3]


ETC ETC CODE HERE

Is this correct/pythonic? Is there a more recommended way? Am I retarded?

Thanks again in advance,
Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Scurvy Scott
> Best practice is to check if your program is being run as a script before
> doing anything. That way you can still import the module for testing or
> similar:
>
>
> def main(mystring, infile, outfile):
># do stuff here
>
>
> if __name__ == '__main__':
># Running as a script.
>import sys
>mystring = sys.argv[1]
>infile = sys.argv[2]
>outfile = sys.argv[3]
>main(mystring, infile, outfile)
>
>
>
> Best practice for scripts (not just Python scripts, but *any* script) is to
> provide help when asked. Insert this after the "import sys" line, before you
> start processing:
>
>if '-h' in sys.argv or '--help' in sys.argv:
>print(help_text)
>sys.exit()
>
>
>
> If your argument processing is more complicated that above, you should use
> one of the three argument parsing modules that Python provides:
>
> http://docs.python.org/2/library/getopt.html
> http://docs.python.org/2/library/optparse.html (deprecated -- do not use
> this for new code)
> http://docs.python.org/2/library/argparse.html
>
>
> getopt is (in my opinion) the simplest to get started, but the weakest.
>
> There are also third-party argument parsers that you could use. Here's one
> which I have never used but am intrigued by:
>
> http://docopt.org/
>
>
>
> --
> Steven
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Steve-
 thanks a lot for showing me the if __name__ = main part
I've often wondered how it was used and it didn't make sense until I
saw it in my own code if that makes any sense.
Also appreciate the help on the "instructional" side of things.

One question related to the instruction aspect- does this make sense to you?

If len(sys.argv) == 0:
print "usage: etc etc etc"



Nick, Dave, and Steve, again, you guys are awesome. Thanks for all your help.

Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read from large text file, parse, find string, print string + line number to second text file.

2013-02-01 Thread Scurvy Scott
And just for the records sake, this is what I've gotten and you guys
should see obviously that you helped a lot and I learned a thing or
two so I won't have to ask the same silly questions next time:




def main(mystring, infile, outfile):
with open('infile', 'r') as inF:
for index, line in enumerate(inF):
if myString in line:
newfile.write("string %s found on line #%d" 
(line, index))
print "complete."


if __name__ == '__main__':
   import sys
   newfile = open('outfile', 'w')
   help_text = "usage: python scanfile.py STRINGTOSEARCH
IMPORTFILENAME OUTPUTFILENAME"
   if '-h' in sys.argv or '--help' in sys.argv or len(sys.argv) == 0:
   print (help_text)
   sys.exit()
   myString = sys.argv[1]
   infile = sys.argv[2]
   outfile = sys.argv[3]
   main(mystring, infile, outfile)

Look right to you? Looks okay to me, except maybe the three ORs in the
information line, is there a more pythonic way to accomplish that
task?

Scott

On Fri, Feb 1, 2013 at 8:31 PM, Scurvy Scott  wrote:
>> Best practice is to check if your program is being run as a script before
>> doing anything. That way you can still import the module for testing or
>> similar:
>>
>>
>> def main(mystring, infile, outfile):
>># do stuff here
>>
>>
>> if __name__ == '__main__':
>># Running as a script.
>>import sys
>>mystring = sys.argv[1]
>>infile = sys.argv[2]
>>outfile = sys.argv[3]
>>main(mystring, infile, outfile)
>>
>>
>>
>> Best practice for scripts (not just Python scripts, but *any* script) is to
>> provide help when asked. Insert this after the "import sys" line, before you
>> start processing:
>>
>>if '-h' in sys.argv or '--help' in sys.argv:
>>print(help_text)
>>sys.exit()
>>
>>
>>
>> If your argument processing is more complicated that above, you should use
>> one of the three argument parsing modules that Python provides:
>>
>> http://docs.python.org/2/library/getopt.html
>> http://docs.python.org/2/library/optparse.html (deprecated -- do not use
>> this for new code)
>> http://docs.python.org/2/library/argparse.html
>>
>>
>> getopt is (in my opinion) the simplest to get started, but the weakest.
>>
>> There are also third-party argument parsers that you could use. Here's one
>> which I have never used but am intrigued by:
>>
>> http://docopt.org/
>>
>>
>>
>> --
>> Steven
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
> Steve-
>  thanks a lot for showing me the if __name__ = main part
> I've often wondered how it was used and it didn't make sense until I
> saw it in my own code if that makes any sense.
> Also appreciate the help on the "instructional" side of things.
>
> One question related to the instruction aspect- does this make sense to you?
>
> If len(sys.argv) == 0:
> print "usage: etc etc etc"
>
>
>
> Nick, Dave, and Steve, again, you guys are awesome. Thanks for all your help.
>
> Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Guidance if possible

2013-04-11 Thread Scurvy Scott
Hello again wonderful python tutor mailing list.

I've got I guess more of a broad question than is usually asked on
this list and perhaps some of you might find it annoying, that's fine,
if it's inappropriate feel free to say so.

I want to start work on a new python project that would visit a
specific companies contest site daily and everyday fill out the active
contest forms, as they allow you to enter once a day.

I've got an outline in my head but am a little green to know any of
the good web scraping/manipulation frameworks or if one is better than
the other for something like this. I have no intention of doing
anything professional/shady/annoying with this code and want to write
it purely for my own amusement as well as to learn and obviously to
perhaps win something cool.

Any information anyone feels like providing would be awesome, I'm
running Lubuntu 12.10, 2gb ram, old crappy notebook.

My basic outline goes something like this..

Everyday the program visits the site and scrapes the links for all the contests.
The program visits each contest page and verifies there is an entry
form, indicating that the contest is active
If the contest is active at that moment, it adds the title of the page
to a text file, if the contest is inactive it adds the title of the
page to a text file.
If the contest is active, it fills out the form with my details and sends it off
If the contest is inactive the title of the page is added to the
permanently blacklisted text file and never messed with again.

This might be a bit convoluted as well and any pointers are appreciated.

Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Generate word list from specified letters

2013-06-30 Thread Scurvy Scott
Hello all.

I'm trying to create a program right now that will pull a dictionary from
urban dictionary, then use that dictionary as the basis for generating
words with specified letters.

Maybe I'm not articulating that well enough..

I'm not at all sure where to start and any guidance would be helpful.

I'm running Debian and Python 2.7

Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Can't figure out why I'm getting no output??

2014-01-28 Thread scurvy scott
Hey all.. First of all here is my code:

import requests
from bs4 import BeautifulSoup as beautiful


payload = {'username': 'X', 'password': 'XX'}
r = requests.post("http://dogehouse.org/index.php?page=login";, data=payload)
soup = beautiful(r.text)
confirmed = str(soup.findAll('span',{'class':'confirmed'}))


print "Confirmed account balance" +confirmed[86:98]

I'm running it on Crunchbang/Debian Linux

I'm trying to write a basic scraper that I can use to output my current
account balance from my mining pool in my terminal.
I've tested the code in the regular python interpreter and it all executes
the way it should. But when I attempt to run it using "python whatever.py"
it doesn't give me any output. Any tips would be appreciated. Thanks.

scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Code runs in interpreter but won't output to stdout

2014-01-29 Thread scurvy scott
Hi guys, I'm trying to figure out why my code won't output to terminal, but
will run just fine in interpreter.
I'm using python 2.7.3 on Debian Linux/Crunchbang.

Here is my code.

import requests
from bs4 import BeautifulSoup as beautiful
import sys

def dogeScrape(username, password):
payload = {'username': username, 'password': password}
r = requests.post("http://dogehouse.org/index.php?page=login";,
data=payload)
soup = beautiful(r.text)
confirmed = str(soup.findAll('span',{'class':'confirmed'}))
print "Confirmed account balance: " + confirmed[86:98]

dogeScrape("", "")

It will output the "confirmed." part, just not the confirmed variable.
It will output the entire thing in the interpreter.

I initially ran this without being in a function with the username/password
stuff hardcoded to see if the rest of the scraper would run, it still never
output to stdout.

Any help would be appreciated.

Also, as an aside, is there a terminal/command line parsing library someone
could recommend? I've been looking at optparse but maybe some of you will
have other ideas.

thanks a lot,
Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Code runs in interpreter but won't output to stdout

2014-02-01 Thread scurvy scott
Please always reply to the tutor list so we can all play with your question.

--sorry about that Bob, I've now hit reply all.

I am stuck at "import requests". Where did you get that module?

--requests is a third party webscraping module.

I signed up at Dogehouse. What the heck is it? There is no explanation as
to what it does or what I'd do with it!

--dogehouse.org is a dogecoin mining pool that allows users to pool CPU/GPU
resources to make mining cryptocurrency more efficient.


Scurvy Scott: There's nothing really special about printing stuff, so
there's something you're not telling us or that you're not aware of
that's causing your program to behave differently between running it
"in the interpreter" and otherwise (from the command line,
presumably.)  Do you for example have multiple versions of Python
installed?  Are you sure for example you're using the same version of
Python interpreter? (print syntax changed between Python 2.x and 3.x.)
 How are you running it from the command line exactly?

Best regards,

Walter

--I'm only using Python 2.7 and yes either running the code live in the
interpreter, which works just fine, or running from command line using
"python programname.py". In this instance, I've named the program
dogeScrape.py, so python dogeScrape.py . I've been messing with python for
a while and have never had this problem before. I've also tried using the
different print syntax for 3.x just to be sure, to no avail.

I've also tried running the code without it being in functions, and just
running it I guess "straight through" or whatever you'd call it, also to no
avail.
The site is implementing its own API in the next week or so, so I just
figured I'd work out these bugs when that happens and maybe some magical
unicorn will cure whatever is ailing me.

Thanks for y'alls help.
Scott


On Sat, Feb 1, 2014 at 5:05 AM, Walter Prins  wrote:

> Hi Bob,
>
> On 31 January 2014 21:59, bob gailer  wrote:
> > On 1/29/2014 8:59 PM, scurvy scott wrote:
> > I signed up at Dogehouse. What the heck is it? There is no explanation
> as to
> > what it does or what I'd do with it!
>
> I don't know if you're familiar with BitCoin and the concept of the
> "pooled mining", but Dogehouse appears to be a bitcoin mining pool.
> Basically instead of mining for bitcoins directly alone by yourself,
> you pool your mining efforts with a pool of others and then share the
> return with the pool: https://en.bitcoin.it/wiki/Pooled_mining
> https://en.bitcoin.it/wiki/Why_pooled_mining
>
> Also, I'm not entirely sure if you were being facetious with your
> "import requests" comment -- I suspect you were and if so I should not
> be commenting on that ;) (and in thaat case please ignore this entire
> paragraph), but in case not -- it's a third party module for doing web
> interaction that's actually been mentioned a couple of times on this
> list: http://docs.python-requests.org/en/latest/
>
> Scurvy Scott: There's nothing really special about printing stuff, so
> there's something you're not telling us or that you're not aware of
> that's causing your program to behave differently between running it
> "in the interpreter" and otherwise (from the command line,
> presumably.)  Do you for example have multiple versions of Python
> installed?  Are you sure for example you're using the same version of
> Python interpreter? (print syntax changed between Python 2.x and 3.x.)
>  How are you running it from the command line exactly?
>
> Best regards,
>
> Walter
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] most useful ide

2014-02-02 Thread scurvy scott
Hi

Are there any recommendations for python ide's

currently I am using idle, which seems pretty decent but am open to any
suggestions


cheers


I personally prefer the Linux interpreter.  Since you're asking.
Scott


On Sun, Feb 2, 2014 at 10:43 AM, Asokan Pichai wrote:

>
>
>
> On Sun, Feb 2, 2014 at 1:55 PM, Ian D  wrote:
>
>> Hi
>>
>> Are there any recommendations for python ide's
>>
>
>> currently I am using idle, which seems pretty decent but am open to any
>> suggestions
>> cheers
>>
>
> While not an IDE in the usual sense I have found IPython a great addition
> to my toolkit.
> YMMV
>
>   Asokan Pichai
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor