Violent_broccoli

- friends
16,607 link karma
8,396 comment karma
send messageredditor for
what's this?

TROPHY CASE

Time Calculator Question by raella69in learnpython

[–]Violent_broccoli 1 point2 points ago

Well you can try something like this then.

def get_time(time):
    t = time.replace('p','').replace('a','').split(':')
    timeplus = 0
    if 'p' in time:  timeplus = 12       
    total_mins =  (int(t[0])+timeplus)*60  + int(t[1])
    print total_mins,  "minutes since midnight"


get_time(raw_input("Time? "))    

Time Calculator Question by raella69in learnpython

[–]Violent_broccoli 0 points1 point ago*

There's probably a better way to do this but here's one:

from datetime import datetime
def get_time(t): return datetime.strptime(t, '%I:%M%p')
elapsed = get_time(raw_input("Time? ").replace('a','AM').replace('p','PM').strip()) - get_time("12:00AM")
print elapsed.seconds/60, "minutes"

Need quick help! by Rampage_Riotin learnpython

[–]Violent_broccoli 0 points1 point ago

Totally forgot the keyerror. Thanks.

Globals and Structure by SomethingMoreUniquein learnpython

[–]Violent_broccoli 2 points3 points ago*

It would help more if you posted the entire code on pastebin to get the bigger picture here. Chances are you might not even need global variables.

[ELI5] Donnie Darko! by rwalin explainlikeimfive

[–]Violent_broccoli 37 points38 points ago

Short version as posted here.

The story is about an alternate "Tangent Universe" that is created sometime before Donnie gets out of bed at the start of the movie. The universe doesn't like Tangents because they can cause a collapse, and so has an "immune response". People (like Frank) who die in the Tangent are called Manipulated Dead and appear as ghosts to push Donnie ("Living Receiver") in the directions he needs to go in order to correct the universe. People close to Donnie (friends, family, teachers) are "Manipulated Living" who also push him toward his destiny, but more subconsciously. The universe grants Donnie special powers like telekinesis to do accomplish this - and eventually the full power of sending the jet engine ("The Artifact") from his mom's plane back in time in order to crash into his room. This will kill him in the past, but also close off the Tangent Universe and save everyone else in the prime universe. Most of the manipulation of Donnie in the movie is about helping him come to terms with the need for this sacrifice.

Long and detailed version here.

And if reading doesn't appeal to you, here's a 10 min video explanation

Python and GoogleAppEngine Possibilities? by imnotthomasin learnpython

[–]Violent_broccoli 1 point2 points ago

I cannot really go into the specifics since I'm pretty new to programming. However from what I understand, they are two completely different things. GAE, as its name states, is an engine for developing and hosting your website and it even provides a database. It happens to include a simple web application framework of its own, called webapp. See it like some sort of easy, but limited quick sitebuilder that you often come across on free webhosts that lets you choose a template and put up a quick site online with only a few customizations.

It might be easy to write a 'Hello world' type app with the default webapp that comes with the appengine. But what happens if you wanted to create a heavy community driven website, with users who are able to sign/post content, commenting system, handling huge requests, cache content and db queries? Or what if you want to write some python directly into your html templates? You'd have to reinvent the wheel.

Django and the others I listed in my previous post, are similar to that webapp, but bigger and they come with those missing batteries that automatically deals with the stuff mentionned above for you. One major advantage of using such framework is that they don't only run on the GAE but on other hosts as well, which makes porting your websites much more easier.

I hope that makes sense.

How would I emulate QBasic's 'GOTO' command in python? by helpmeoutguyin learnpython

[–]Violent_broccoli 4 points5 points ago*

You could also use a list, it'll make your life easier.

import random

def fcookie():

    cookies = ["Help! I'm trapped in a fortune cookie factory!",
            "Live long and prosper",
            "Please return to 261 12th Street Oakland",
            "Look behind you",
            "Red fish blue fish..",
            ]
    return random.choice(cookies)

if __name__ == "__main__":
    run = True
    print("\n\t\tWelcome to shitty fortune cookie game!\n\t\tPress any key to start..\n\t\tOr type 'quit' to exit")

    while run:
        choice = input("\n")
        if choice == 'quit':
            print("Thanks for playing")
            run = False         
        else: 
            print(fcookie())

edit : absolutedestiny's suggestion

Python and GoogleAppEngine Possibilities? by imnotthomasin learnpython

[–]Violent_broccoli 1 point2 points ago*

Yes you can build full fledged websites on the GAE. The GAE scales well and the DataStore can handle large amounts of data. The limitation lies within the quota of the free instances/apps not within its capabilities.

Just like Ruby on Rails, there are a lot of full-fledged webframeworks for python which are more scalable than the standard webapp you're using like: Django, web2py, Flask(?), Pyramid etc... Consider using one of them instead of reinventing the wheel. Doesn't mean you won't have to code the entire site, they make handling the core stuff like, requests, caching, db for example, much easier and lets you focus more on your site.

Here's an example of a blog running on the app engine and made with the web2py framework which has a one-click GAE deployment button. They have a facebook clone and a reddit clone on their too but can't find the links right now.

edit- here's another app from the same framework that can be deployed on the appengine. To give you an idea of the possibilities.

Stripping help with dictionary by seminole21in learnpython

[–]Violent_broccoli 1 point2 points ago

Did you integrate this with some some other code? If yes post the whole code here. And what version of python are you using?

Stripping help with dictionary by seminole21in learnpython

[–]Violent_broccoli 1 point2 points ago*

Maybe something like this?

stock = {}
prod = raw_input('Please enter the name of the product you would like to add:\n')
qty = raw_input("Please enter the quantity of the product\n")
price = raw_input("Please enter the price of the product\n" )
stock[prod] = {"Quantity":qty, "Price":price}

infile=open("grocery_stock.txt", 'a')
for i in stock:
    formatting = "Product: %s || Quantity: %s , Price: %s \n" %(i, stock[i]['Quantity'], stock[i]['Price'])
    infile.write(formatting)
infile.close()

Though the dictionary is unecessary here unless you'd want to keep some form of database in a second file.

Help with RE and isolating numbers from HTML by Puzzelin learnpython

[–]Violent_broccoli 0 points1 point ago

from urllib.error import HTTPError

Help with RE and isolating numbers from HTML by Puzzelin learnpython

[–]Violent_broccoli 0 points1 point ago*

Yep except I get it on every single run. Even when I haven't requested anything before for a long time (hours, days). Started getting this since the start of this year.

Help with RE and isolating numbers from HTML by Puzzelin learnpython

[–]Violent_broccoli 0 points1 point ago

Weirdly I'm getting a lot of HttpError 429 when I use the regular urlopen.

Help with RE and isolating numbers from HTML by Puzzelin learnpython

[–]Violent_broccoli 5 points6 points ago*

Instead of loading the entire html source code into memory, why not use reddit's json service. E.g append ".json" to any url

from urllib2 import urlopen
from json import loads
from sys import argv


def karma(user):
    url = urlopen("http://www.reddit.com/user/%s/about.json"%user)
    data = loads(url.read())['data']
    url.close()
    link_karma = data['link_karma']
    comment_karma = data['comment_karma']
    print "User:%s \nLink Karma:%s \nComment Karma:%s" %(user, link_karma, comment_karma)
    return link_karma, comment_karma

if __name__ == "__main__":
    try:
        karma(argv[1])
    except IndexError:
        print "Specify a username e.g \n python karma.py puzzel"

edit : using urlopen instead

[meta] A request to the proprietor of /u/DramaScreenshot by mikemcgin SubredditDrama

[–]Violent_broccoli 1 point2 points ago

Alternatively,

  • make an empty .html page on your server
  • log in with your bot through the api
  • copy the source code of the reddit thread to that empty .html
  • link your third-part screenshot service to the url of that .html instead of reddit
  • upload to imgur
  • post on reddit
  • repeat/overwrite
  • ????
  • drama!

Need help on a threaded commenting system's logic. by Violent_broccoliin learnpython

[–]Violent_broccoli[S] 0 points1 point ago

Fantastic and much more elegant. The order shouldn't be a problem either. Thank you this is exactly what I was looking for!

Help me to understand "class" and "def" by otac_jediniin learnpython

[–]Violent_broccoli 3 points4 points ago

import random
class RandomTime(object):

    def low(self):
        return random.randrange(3,12)

    def med(self):
        return random.randrange(12,25)

    def high(self):
        return random.randrange(25,63)


x = RandomTime()
print x.low(),  x.med(), x.high()

Writing a variation of Snip Tool that will automatically upload my screenshot to Imgur. Any ideas how to do the uploading bit? by lyndisin learnpython

[–]Violent_broccoli 0 points1 point ago

Thanks, I didn't know. This is way more practical for multiple uploads.

view more: next