Exemplo n.º 1
0
def download(chapters, window, path):
    downloader = Downloader()
    chapters_nums = len(chapters)
    for i, chapter in enumerate(chapters):
        downloader.download(chapter, path)
        progress = int((i + 1) / chapters_nums * 100)
        window['-PROGRESS-'].UpdateBar(progress)
Exemplo n.º 2
0
def upload(request, json=False):
    if request.method == 'GET':
        form = UploadForm()

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            data = request.FILES['file']
            size = form.cleaned_data['file'].size
            expire_date = form.cleaned_data['expire_date'] or one_week_later()
            message = form.cleaned_data['message']
            receiver = form.cleaned_data['receiver']

            if form.cleaned_data['filename_overwrite']:
                name = form.cleaned_data['filename_overwrite']
            else:
                name = form.cleaned_data['file'].name

            file = File(name=name, owner=request.user,
                        expire_date=expire_date, message=message, size=size)

            md5 = handle_uploaded_file(name, file.secret, data)
            file.md5 = md5
            file.save()

            if receiver:
                downloader = Downloader(email=receiver, file=file)
                downloader.save()
                url = 'http://%s/files/download/%s/%s' % \
                    (Site.objects.get_current().domain, file.id, file.secret)
                from_ = request.user.email
                mailit([receiver], from_, message, url)

            if json:
                response = {'status': 'ok', 'fileid': file.id}
                return HttpResponse(simplejson.dumps(response))
            else:
                return HttpResponseRedirect('/files/list/')

    if json:
        response = {'status': 'error', 'message': 'form not valid'}
        return HttpResponse(simplejson.dumps(response))
    else:
        return render_to_response('files/upload.html', {'form': form, }, context_instance=RequestContext(request))
Exemplo n.º 3
0
    def get(self, request):
        # response
        response = {
            'success': 0,
            'message': "Failed to download.",
        }

        # get app
        app = self.request.GET.get('app', None)

        # get name
        rows = self.request.GET.get('rows', None)

        # get headers
        headers = self.request.GET.get('headers', None)

        # get fields needs to be excluded
        excluded = list()
        try:
            excluded = eval(self.request.GET.get('excluded', None))
        except Exception as e:
            pass

        # maximum no. of rows in excel
        max_rows = self.request.GET.get('max_rows', None)

        if app and rows and headers:
            # get current user name
            username = self.request.user.username

            timestamp = time.time()
            fulltime = datetime.fromtimestamp(timestamp).strftime(
                '%Y-%m-%d-%H-%M-%S')

            # downloader object
            d_obj = Downloader()
            d_obj.app_name = app
            d_obj.headers_view = headers
            d_obj.rows_view = rows
            d_obj.downloaded_by = username
            d_obj.status = 2
            d_obj.description = "Failed to download on {}.".format(fulltime)

            # get rows and headers request data
            headers_data = ""
            rows_data = ""
            advance_filter = ""
            try:
                rows_data = eval(self.request.GET.get('rows_data', None))
                headers_data = eval(self.request.GET.get('headers_data', None))
                # get advance filtering object
                try:
                    advance_filter = self.request.GET.get(
                        'advance_filter', None)
                    rows_data['advance_filter'] = advance_filter
                except Exception, e:
                    logger.info(e.message)
                    pass
                response[
                    'message'] = "Inventory download started. Please check status \
                <a href='/downloader/' target='_blank'>Here</a>."

                response['success'] = 1
                d_obj.status = 0
                d_obj.description = "Start downloading on {}.".format(fulltime)
            except Exception as e:
                response['message'] = "Wrong data format."
Exemplo n.º 4
0
from __future__ import unicode_literals
from models import Downloader

if __name__ == '__main__':
    print 'GitHub File Downloader 0.2'
    print "Please make sure that directory 'downloads' exists in a script's " \
          "directory"
    link = raw_input('Pass link to download: ')
    file_types = raw_input(
        '\nPass type of files to download (e.g. jpg;txt) or leave blank for '
        'any type: ')
    if file_types:
        file_types = file_types.split(';')
    else:
        file_types = list()
    downloader = Downloader(link, file_types)
    downloader.download()
    print '\nFinished downloading'