Ejemplo n.º 1
0
def iepginput(d):
    a_title = Title(name=d['program-title'])
    b_waves = Waves(name=d['station'])
    c_station = Station(name=d['station-name'])
    d_comments = Comments(name=d['comment'])
    op = timeset(d, start)
    ed = timeset(d, end)
    sg1 = d['genre-1'] * 16 + d['subgenre-1']
    if d['genre-2'] == 0:
        x = Program(title=a_title,
                    program_id=d['program-id'],
                    waves=b_waves,
                    station=c_station,
                    start=op,
                    end=ed,
                    gen_1=d['genre-1'],
                    sgn_1=sg1,
                    comments=d_comments)
        x.save
    else:
        sg2 = d['genre-2'] * 16 + d['subgenre-2']
        x = Program(title=a_title,
                    program_id=d['program-id'],
                    waves=b_waves,
                    station=c_station,
                    start=op,
                    end=ed,
                    gen_1=d['genre-1'],
                    sgn_1=sg1,
                    gen_2=d['genre-2'],
                    sgn_2=sg2,
                    comments=d_comments)
        x.save
Ejemplo n.º 2
0
def updatePrograms(channel, week_id, c_id):
    maked_url = URL % (c_id, week_id)
    response = urlopen(maked_url)
    html = response.read()
    response.close()
    filtered_list = re.findall(r'<td.*?><span.*?>(.*?)</span></td>',html)
    for i in range(0,len(filtered_list),2):
        time = filtered_list[i]
        name = filtered_list[i+1].decode('utf-8')
        p = Program( day=week_id, time = time, name = name, channel = channel)
        p.put()
Ejemplo n.º 3
0
 def new_program(token):
     try:
         body = request.get_json()
         if body is None:
             abort(404)
         new_division = body.get('division')
         new_director = body.get('director')
         new_program = Program(division=new_division, director=new_director)
         new_program.insert()
         new_program = Program.query.filter_by(id=new_program.id).first()
         return jsonify({'success': True, 'programs': [new_program.long()]})
     except:
         abort(401)
def addProgram(genre_id):
    """Add a program to specified genre.

    Args:
        genre_id (int): Primary key of specified genre.

    Returns:
        If user is not signed in, redirect to login page.
        on GET: Page with form for user to submit new program details.
        on POST: Redirect to read-only page showing program details.
    """
    if request.method == 'GET':
        genres = session.query(Genre).order_by('name').all()
        genre = session.query(Genre).filter_by(id=genre_id).one()
        return render_template('addProgram.html', genres=genres, genre=genre)
    elif request.method == 'POST':
        name = request.form.get('name')
        yearBegan = request.form.get('yearBegan')
        yearEnded = request.form.get('yearEnded')
        description = request.form.get('description')
        user_id = login_session['user_id']

        numPrograms = session.query(Program).filter_by(genre_id=genre_id,
                                                       name=name).count()
        if numPrograms > 0:
            flash('The program you are attempting to add already exists.')
            return redirect(request.path)
        program = Program(name=name, yearBegan=yearBegan, yearEnded=yearEnded,
                          description=description, genre_id=genre_id,
                          user_id=user_id)
        session.add(program)
        session.commit()
        flash("Program \"%s\" created." % program.name)
        return redirect(url_for('showProgram', genre_id=genre_id,
                                program_id=program.id))
    def get(self):

        role = self.session.get('role')
        user_session = self.session.get("user")

        if role != "admin" and role != "staff":
            self.redirect("/users/login?message={0}".format(
                "You are not authorized to view this page"))
            return

        if not self.legacy:
            self.redirect("/#/admin/programs/new")

        form = Program.NewProgramForm()
        template_values = {"form": form, "user_session": user_session}
        language = None
        if "language" in self.request.cookies:
            language = self.request.cookies["language"]
        else:
            language = "fr"
            self.response.set_cookie("language", "fr")

        language = language.replace('"', '').replace("'", "")
        if language == "fr":

            LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                'fr_new_programs.html')
        else:
            LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                'new_programs.html')
        self.response.write(LEGACY_TEMPLATE.render(template_values))
def create_programs(programs):
    for prog in programs:
        program_id = generate_random_uuid()
        program = Program(program_id=program_id,
                          name=programs[prog]['name'],
                          description=programs[prog]['description'])
        add_and_commit(program)
        programs[prog]['program_id'] = program_id
Ejemplo n.º 7
0
def updateInfo(key, gogo_id):
    channel = Channel.get(key)
    programs = list(Program.gql("WHERE channel = :channel", channel = channel))
    for p in programs:
        p.delete()
    for day in range(1,8): #iterate week
        logging.info('updating info of ' + channel.name)
        try:
            updatePrograms(channel, day, gogo_id)
        except Exception, e:
            logging.error('error happened, while updating: ' + e.message)
Ejemplo n.º 8
0
def add_program(request):
    #title = request.POST["title"]
    #description = request.POST["description"]
    user = request.POST["owner"]
    print user
    owner = User.objects.get(google_id=user)
    content = request.POST["content"]
    content = content.encode('utf-8')
    print owner
    print "before printing out content in add_program"
    print content
    program = Program(
            #title = title,
            #description = description,
            owner = owner,
            content = content
            )
    program.save()
    data = {'content':program.content, 'owner':program.owner.google_id, 'id':program.id}
    response_data = {'data':data}
    return HttpResponse(json.dumps(response_data), content_type="application/json")
Ejemplo n.º 9
0
def program_upload(request):

  user = request.user

  if request.method == 'POST':
    if user.is_authenticated():

      file = request.FILES.get('filename', '')

      file_name = file.name
      dest_dir = os.path.join(settings.USR_PROGRAM_ROOT, user.username)
      if not os.path.exists(dest_dir):
        os.makedirs(dest_dir)
				# os.chmod(dest_dir, 0775)

      full_path = os.path.join(dest_dir, file_name)
      destination = open(full_path, "wb+")
      for chunk in file.chunks():
        destination.write(chunk)
      destination.close()

      language = request.POST['lang']
      description = request.POST['description']
      access = request.POST['access']
      new_program = Program(owner = user, path = full_path, name = file_name, language = language, description = description, access = access)
      new_program.save()

      notice = "Congratulations! Your model has been successfully uploaded."
      return render_to_response('program/success.html', RequestContext(request, {'program': new_program, 'notice': notice}))

    else:
      notice = "You must be logged in to upload programs"
      form = UploadProgramForm()
      return render_to_response('program/upload.html', RequestContext(request, {'form': form, 'notice': notice}))

  else:
    form = UploadProgramForm()
    return render_to_response('program/upload.html', RequestContext(request, {'form': form}))
Ejemplo n.º 10
0
    def save_to_db(self):
        """Saves the current program to the database and destroys the display"""
        name = self.name_entry.get()
        if not name:
            # TODO: do something here that warns them I guess
            return

        option = self.dropdown.get()

        try:
            program = self.program_dict[option]
        except KeyError:
            # TODO: warning thingy like above
            return

        to_add = Program(name=name,
                         process_name=program.name(),
                         location=program.exe())
        session.add(to_add)
        session.commit()

        self.destroy()
Ejemplo n.º 11
0
def main():
    options = parse_args()

    if options.explain:
        with open(options.explain) as f:
            program = json.load(f)
        print("==== \033[1mExpected tape input format:\033[0m ==== ")
        print(program.get('tape-format', '<not provided>'))
        print()
        print("==== \033[1mExpected tape output format:\033[0m ====")
        print(program.get('output-format', '<not provided>'))
        return

    program = Program.from_file(options.program)
    tape = [i for i in options.tape]

    if options.accepts:
        print(
            TuringMachine.accepts(program,
                                  tape,
                                  error_on_eot=not options.infinite,
                                  verbose=not options.quiet))
        return

    machine = TuringMachine(program,
                            tape,
                            err_on_eot=not options.infinite,
                            verbose=not options.quiet)
    if options.ensuretransitions:
        machine.ensure_transitions()
    print("Machine start!")
    print("Tape output (without blanks)")
    machine.print_tape_trimmed()
    if not options.quiet:
        print("\nBeginning simulation...")
    machine.run()
    print('\nFinished!')
    print("Tape output (without blanks)")
    machine.print_tape_trimmed()
Ejemplo n.º 12
0
def sendBadgeMail(from_email, from_name, contribution, mentor, admin, reply_to, merge, to_name, twitter):
    sendmail = False
    contributed_hours = contribution.get("new_total")

    badge_category = ""
    badge_name = ""

    contributors_first_name = mentor.first_name

    program = Program.all().filter("user = "******" " + mentor.last_name
    subject = "[MSF] %s just earned a new badge!" % (to_name_mentor)
    mentor_subject = "[MSF] You've earned a new badge!"
    tags = "New badge earned"

    if contributed_hours >= 250 and program.grand_master == None:
        sendmail = True
        badge_category = "GRAND MASTER"
        badge_name = "Badge250"
        program.scout_master = True
        program.sensei = True
        program.captain = True
        program.general = True
        program.grand_master = True
        program.put()

    elif contributed_hours >= 100 and program.general == None:
        sendmail = True
        badge_category = "GENERAL"
        badge_name = "Badge100"
        program.scout_master = True
        program.sensei = True
        program.captain = True
        program.general = True
        program.put()

    elif contributed_hours >= 50 and program.captain == None:
        sendmail = True
        badge_category = "CAPTAIN"
        badge_name = "Badge50"
        program.scout_master = True
        program.sensei = True
        program.captain = True
        program.put()

    elif contributed_hours >= 25 and program.sensei == None:
        sendmail = True
        badge_name = "Badge25"
        badge_category = "SENSEI"
        program.scout_master = True
        program.sensei = True
        program.put()

    elif contributed_hours >= 10 and program.scout_master == None:
        sendmail = True
        badge_name = "Badge10"
        badge_category = "SCOUT MASTER"
        program.scout_master = True
        program.put()

    to_email_mentor = mentor.email
    html_mentor = mailContent.newbadge
    variables_mentor = [
        {"name": "contributors_first_name", "content": contributors_first_name},
        {"name": "contributed_hours", "content": contributed_hours},
        {"name": "server_url", "content": access.server_url},
        {"name": "badge_name", "content": badge_name},
        {"name": "badge_category", "content": badge_category},
    ]

    to_email_admin = admin.email
    to_name_admin = to_name
    html_admin = mailContent.newbadgeadmin
    variables_admin = [
        {"name": "contributors_full_name", "content": to_name_mentor},
        {"name": "badge_category", "content": badge_category},
        {"name": "contributed_hours", "content": contributed_hours},
        {"name": "server_url", "content": access.server_url},
        {"name": "twitter", "content": twitter},
        {"name": "contributors_first_name", "content": contributors_first_name},
    ]
    if sendmail:
        try:
            mentor_mail = sendOutboundMail(
                from_email,
                from_name,
                to_email_mentor,
                to_name_mentor,
                mentor_subject,
                html_mentor,
                tags,
                reply_to,
                variables_mentor,
                merge,
            )
            admin_mail = sendOutboundMail(
                from_email,
                from_name,
                to_email_admin,
                to_name_admin,
                subject,
                html_admin,
                tags,
                reply_to,
                variables_admin,
                merge,
            )
            return True
        except:
            return False

    return True
Ejemplo n.º 13
0
 def post(self):
     form = Program.NewProgramForm(self.request.POST)
     if form.validate():
         user = Program.save(self, form, LEGACY_TEMPLATE)
     else:
         self.response.write(LEGACY_TEMPLATE.render({"form": form}))
Ejemplo n.º 14
0
def sendBadgeMail(from_email, from_name, contribution, mentor, admin, reply_to, merge, to_name):
    sendmail = False
    contributed_hours = contribution.get("new_total")

    badge_category = ""
    badge_name = ""

    contributors_first_name = mentor.first_name

    program = Program.all().filter("user = "******" " + mentor.last_name
    subject = "%s just earned a new badge!" %(to_name_mentor)
    tags = "New badge earned"

    if contributed_hours >= 50 and program.guru == None:
        sendmail = True
        badge_category = "GURU"
        badge_name = "Badge50"
        program.guru = True
        program.ninja = True
        program.rock_star = True
        program.put()
    
    elif contributed_hours >= 25 and program.ninja == None:
        sendmail = True
        badge_name = "Badge25"
        badge_category = "NINJA"
        program.ninja = True
        program.rock_star = True
        program.put()
    
    elif contributed_hours >= 10 and program.rock_star == None:
        sendmail = True
        badge_name = "Badge10"
        badge_category = "ROCK STAR"
        program.rock_star = True
        program.put()
    
    to_email_mentor = mentor.email
    html_mentor = mailContent.newbadge
    variables_mentor = [
                    {'name':'contributors_first_name', 'content': contributors_first_name},
                    {'name':'contributed_hours', 'content': contributed_hours},
                    {'name':'badge_name', 'content': badge_name},
                    {'name':'badge_category', 'content': badge_category}
                ] 
    
    to_email_admin = admin.email
    to_name_admin = to_name
    html_admin = mailContent.newbadgeadmin
    variables_admin = [
                    {'name':'contributors_full_name', 'content': to_name_mentor},
                    {'name':'badge_category', 'content': badge_category},
                    {'name':'contributed_hours', 'content': contributed_hours},
                    {'name':'contributors_first_name', 'content': contributors_first_name}
                ]
    if  sendmail:
        try:
            mentor_mail  =  sendOutboundMail(from_email, from_name, to_email_mentor, to_name_mentor, subject, html_mentor, tags, reply_to, variables_mentor, merge) 
            admin_mail   =  sendOutboundMail(from_email, from_name, to_email_admin, to_name_admin, subject, html_admin, tags, reply_to, variables_admin, merge)        
            return True
        except:
            return False

    return True