Re: Django - Pass a model instance specified by template tags to the view

2017-11-09 Thread Adam Simon
I would recommend taking a look at how Jquey does Ajax. It’s a lot simpler
than Django forms. I will post some example code when I get home


On Thu, Nov 9, 2017 at 3:42 PM Jack Zhang  wrote:

> No I am not familiar with Ajax.  I only know a bit of JavaScript.
> ᐧ
>
> On Thu, Nov 9, 2017 at 6:19 PM, Adam Simon 
> wrote:
>
>>
>> Hi Jack. I will write some more details when I get home. Have you ever
>> used Ajax?
>>
>> On Thu, Nov 9, 2017 at 3:14 PM Jack  wrote:
>>
>>> Ok I'm very stuck.  Thought very hard about it but can't see how I can
>>> add a hidden field into the HTML, and relay the specified instance of the
>>> hidden field back to the views... or am I completely off about something?
>>>
>>> Also in regards to the looped form's.  If you look at my original code,
>>> I actually do have a  representing a button for each agent.  The
>>> resulting page looks like this
>>>  (excuse the
>>> bad CSS).  I'm not sure if that is what you meant by having a form for each
>>> agent.
>>>
>>> So if I understood you correctly, I do have a separate  input for
>>> each displayed agent; looped with {% for agent in agent_list %}.  The
>>> question is, how do I relay the correct agent linked to its 'Send Invite'
>>> button back to the views?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/eab1a4c0-2cc1-41d0-aace-f8ef3fd73112%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> --
>>
>> Adam F. Simon, PhD
>> Calabasas, CA.
>>
>> cell:  818-425-3719 <(818)%20425-3719>
>> home:   818-880-8405 <(818)%20880-8405>
>>
>> Feel free to link w/ me: LinkedIn
>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/k5mwo58aPfU/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> django-users+unsubscr...@googlegroups.com.
>
>
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>>
> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAH-jdcw11Z1w2qRCkuwzdXL0qFNXD1PkLJsw6sRSVHNDBfWAfQ%40mail.gmail.com
>> 
>> .
>
>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
>
> *Jack Zhang*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFoBqVb8fnSgFDb451yhZavF3gdguKxYj%3DAPnpSYq3c2sEyZ8w%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
-- 

Adam F. Simon, PhD
Calabasas, CA.

cell:  818-425-3719
home:   818-880-8405

Feel free to link w/ me: LinkedIn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAH-jdczXzQ2SOQoMoi1EGsSMy5e6ZbS%2BKHFzmiijEewf5uLhrQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django - Pass a model instance specified by template tags to the view

2017-11-09 Thread Jack Zhang
No I am not familiar with Ajax.  I only know a bit of JavaScript.
ᐧ

On Thu, Nov 9, 2017 at 6:19 PM, Adam Simon  wrote:

>
> Hi Jack. I will write some more details when I get home. Have you ever
> used Ajax?
>
> On Thu, Nov 9, 2017 at 3:14 PM Jack  wrote:
>
>> Ok I'm very stuck.  Thought very hard about it but can't see how I can
>> add a hidden field into the HTML, and relay the specified instance of the
>> hidden field back to the views... or am I completely off about something?
>>
>> Also in regards to the looped form's.  If you look at my original code, I
>> actually do have a  representing a button for each agent.  The
>> resulting page looks like this
>>  (excuse the
>> bad CSS).  I'm not sure if that is what you meant by having a form for each
>> agent.
>>
>> So if I understood you correctly, I do have a separate  input for
>> each displayed agent; looped with {% for agent in agent_list %}.  The
>> question is, how do I relay the correct agent linked to its 'Send Invite'
>> button back to the views?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/eab1a4c0-2cc1-41d0-aace-f8ef3fd73112%
>> 40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> --
>
> Adam F. Simon, PhD
> Calabasas, CA.
>
> cell:  818-425-3719 <(818)%20425-3719>
> home:   818-880-8405 <(818)%20880-8405>
>
> Feel free to link w/ me: LinkedIn
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/k5mwo58aPfU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAH-jdcw11Z1w2qRCkuwzdXL0qFNXD1PkL
> Jsw6sRSVHNDBfWAfQ%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 

*Jack Zhang*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFoBqVb8fnSgFDb451yhZavF3gdguKxYj%3DAPnpSYq3c2sEyZ8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django - Pass a model instance specified by template tags to the view

2017-11-09 Thread Adam Simon
Hi Jack. I will write some more details when I get home. Have you ever used
Ajax?

On Thu, Nov 9, 2017 at 3:14 PM Jack  wrote:

> Ok I'm very stuck.  Thought very hard about it but can't see how I can add
> a hidden field into the HTML, and relay the specified instance of the
> hidden field back to the views... or am I completely off about something?
>
> Also in regards to the looped form's.  If you look at my original code, I
> actually do have a  representing a button for each agent.  The
> resulting page looks like this
>  (excuse the
> bad CSS).  I'm not sure if that is what you meant by having a form for each
> agent.
>
> So if I understood you correctly, I do have a separate  input for
> each displayed agent; looped with {% for agent in agent_list %}.  The
> question is, how do I relay the correct agent linked to its 'Send Invite'
> button back to the views?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/eab1a4c0-2cc1-41d0-aace-f8ef3fd73112%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
-- 

Adam F. Simon, PhD
Calabasas, CA.

cell:  818-425-3719
home:   818-880-8405

Feel free to link w/ me: LinkedIn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAH-jdcw11Z1w2qRCkuwzdXL0qFNXD1PkLJsw6sRSVHNDBfWAfQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django - Pass a model instance specified by template tags to the view

2017-11-09 Thread Jack
Ok I'm very stuck.  Thought very hard about it but can't see how I can add 
a hidden field into the HTML, and relay the specified instance of the 
hidden field back to the views... or am I completely off about something?

Also in regards to the looped form's.  If you look at my original code, I 
actually do have a  representing a button for each agent.  The 
resulting page looks like this 
 (excuse the bad 
CSS).  I'm not sure if that is what you meant by having a form for each 
agent.

So if I understood you correctly, I do have a separate  input for 
each displayed agent; looped with {% for agent in agent_list %}.  The 
question is, how do I relay the correct agent linked to its 'Send Invite' 
button back to the views?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eab1a4c0-2cc1-41d0-aace-f8ef3fd73112%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I pass the CSRF token when using a jQuery post

2017-11-09 Thread Tony King

Thanks Gourav,

I have it working now and I can even understand it, which is even better.  
For anyone interested my revised working solution is below.

I'm sure it would be better practice putting the token into the headers as 
described in the documentation and elsewhere but I could not get it to work.


{% load static %}




https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js";>



{% csrf_token %}

{{ hdr1 }}




{% if my_apps_list %}
{% for my_apps in my_apps_list %}





$("#app{{ forloop.counter }}").click( function() {
document.getElementById('hdr_1').innerHTML = 'Hello World!';
$.ajax({
url : "{% url 'launch' %}",
type: "POST",
data: { csrfmiddlewaretoken: document.getElementsByName(
'csrfmiddlewaretoken')[0].value,
appname: '{{ my_apps.app_name }}',
apppath: '{{ my_apps.app_path }}',
appexe: '{{ my_apps.app_exe }}',
appargs: '{{ my_apps.app_args }}',
appusr: '{{ my_apps.app_user }}',
apppwd: '{{ my_apps.app_pwd }}',
applook4: '{{ my_apps.app_wait4 }}',
appdelay: '{{ my_apps.app_delay }}',
appkeys: '{{ my_apps.app_keys }}'},
dataType : "json",
success: function( msg ){
document.getElementById('appstatus').innerHTML = msg;
}
});
});


{% endfor %}






{% else %}
No applications are available.
{% endif %}



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1bc91f14-bd24-4c84-929a-ad6302cf7709%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django - Pass a model instance specified by template tags to the view

2017-11-09 Thread Adam Simon
Each form would be generated by a loop; still I would go with the hidden
field.

Look forward to seeing how it goes.


On Thu, Nov 9, 2017 at 6:46 AM Jack  wrote:

> There will be a lot of agents in the database, so would it violate the DRY
> principle if I were to write a form for each agent?  Plus it'll be super
> time consuming.
>
> I'm going to try the hidden agent.id thing, I never thought about that.
> I'll report back to see if I managed to get it working.
>
> On Wednesday, November 8, 2017 at 6:24:29 PM UTC-5, Adam wrote:
>>
>>
>> On Wed, Nov 8, 2017 at 1:38 PM Jack  wrote:
>>
> On my HTML page, I have a list of Agent's (Agent is my custom User
>>> model).  Beside each agent is a 'Send Invite' button.  To create a
>>> `TeamInvitation`, I need to specify which Agent is attached to its
>>> `receiver_agent` field (a OneToOneField with Agent)
>>>
>>> There are multiple Agents displayed on the HTML page, and they are
>>> listed in order with template tags.  I need to input something after `pk`
>>> at `receiver_agent = Agent.objects.get(pk = ???)`, but I don't know what to
>>> input.
>>>
>>> *views.py*
>>>
>>> class InviteAgentSearchResults(ListView):
>>> model = Agent
>>> form_class = AgentSearchForm
>>> template_name = 'invite_agent_search_results.html'
>>>
>>> def get_queryset(self):
>>> # ... Code to find correct list of agents
>>>
>>> def post(self, request, *args, **kwargs):
>>> invite = TeamInvitation.objects.create(receiver_agent =
>>> Agent.objects.get(pk = ???))
>>> return HttpResponse('Invite successfully sent.')
>>>
>>> *HTML:*
>>>
>>> {% for agent in agent_list %}
>>> 
>>> # ... Some code here
>>>
>>>   # The "Send Invite" button
>>> {% csrf_token %}
>>> Send Invite
>>> 
>>> 
>>> {% endfor %}
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>>
>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>
>>
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/bd0439e2-7fdd-4f7c-b6ce-4847d4a877c8%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> It seems to me that the quickest thing would be to make each agent a
>> separate form.
>>
>> Alternatively, you could set up some JavaScript:
>>
>> Add the agent.id to a hidden input,  separated by commas, and have that
>> hidden field submitted via the form
>>
>> Then on the backend separate out each ID and have the invites sent one by
>> one. I would be happy to write some code if you wish.
>>
>>
>> --
>> --
>>
>> Adam F. Simon, PhD
>> Calabasas, CA.
>>
>> cell:  818-425-3719
>> home:   818-880-8405
>>
>> Feel free to link w/ me: LinkedIn
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/49997913-66f3-416d-847e-d2ba69459f0c%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
-- 

Adam F. Simon, PhD
Calabasas, CA.

cell:  818-425-3719
home:   818-880-8405

Feel free to link w/ me: LinkedIn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAH-jdcynxsBd0JoBqf0tX9SdutSFzS%3DfJ0twMW9s5C%3DOpe4Hhg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django - Pass a model instance specified by template tags to the view

2017-11-09 Thread Jack
There will be a lot of agents in the database, so would it violate the DRY 
principle if I were to write a form for each agent?  Plus it'll be super 
time consuming.

I'm going to try the hidden agent.id thing, I never thought about that.  
I'll report back to see if I managed to get it working. 

On Wednesday, November 8, 2017 at 6:24:29 PM UTC-5, Adam wrote:
>
>
> On Wed, Nov 8, 2017 at 1:38 PM Jack  
> wrote:
>
>> On my HTML page, I have a list of Agent's (Agent is my custom User 
>> model).  Beside each agent is a 'Send Invite' button.  To create a 
>> `TeamInvitation`, I need to specify which Agent is attached to its 
>> `receiver_agent` field (a OneToOneField with Agent)
>>
>> There are multiple Agents displayed on the HTML page, and they are listed 
>> in order with template tags.  I need to input something after `pk` at 
>> `receiver_agent = Agent.objects.get(pk = ???)`, but I don't know what to 
>> input.
>>
>> *views.py*
>>
>> class InviteAgentSearchResults(ListView):
>> model = Agent
>> form_class = AgentSearchForm
>> template_name = 'invite_agent_search_results.html'
>> 
>> def get_queryset(self):
>> # ... Code to find correct list of agents
>> 
>> def post(self, request, *args, **kwargs):
>> invite = TeamInvitation.objects.create(receiver_agent = 
>> Agent.objects.get(pk = ???))
>> return HttpResponse('Invite successfully sent.')
>>
>> *HTML:*
>>
>> {% for agent in agent_list %}
>> 
>> # ... Some code here
>>
>>   # The "Send Invite" button
>> {% csrf_token %}
>> Send Invite
>> 
>> 
>> {% endfor %}
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/bd0439e2-7fdd-4f7c-b6ce-4847d4a877c8%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> It seems to me that the quickest thing would be to make each agent a 
> separate form. 
>
> Alternatively, you could set up some JavaScript:
>
> Add the agent.id to a hidden input,  separated by commas, and have that 
> hidden field submitted via the form
>
> Then on the backend separate out each ID and have the invites sent one by 
> one. I would be happy to write some code if you wish.
>
>
> -- 
> -- 
>
> Adam F. Simon, PhD
> Calabasas, CA.
>
> cell:  818-425-3719
> home:   818-880-8405
>
> Feel free to link w/ me: LinkedIn
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/49997913-66f3-416d-847e-d2ba69459f0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: executing python script in html button

2017-11-09 Thread Vineet Kothari
Use bokeh

On Nov 9, 2017 1:44 PM, "Derek"  wrote:

> Hi
>
> Its unlikely anyone on this list will write your code - but the good news
> is that are lots of helpful tutorials from which you can learn to do this;
> for example:
>
> * https://docs.djangoproject.com/en/1.11/intro/tutorial04/
> * https://tutorial.djangogirls.org/en/django_forms/
> * https://www.simplifiedpython.net/django-forms-tutorial-working-forms/
>
> Its likely though, that you might need to work through some of the other
> material so you can understand how and where forms fit into the overall
> Django approach.
>
> Hope this helps
> Derek
>
>
> On Friday, 3 November 2017 18:08:58 UTC+2, Rizal M. wrote:
>>
>> I have custom python script for twitter sentiment analysis, let's call it
>> sentiment.py
>> it has two inputs, topic query and number of tweets.
>>
>> this is the full code
>>
>> import sys
>> import csv
>> import tweepy
>> import matplotlib.pyplot as plt
>>
>> from collections import Counter
>> from aylienapiclient import textapi
>>
>> if sys.version_info[0] < 3:
>>input = raw_input()
>>
>> ## Twitter credentials
>> consumer_key = "xxx"
>> consumer_secret = "xxx"
>> access_token = "xxx"
>> access_token_secret = "xxx"
>>
>> ## AYLIEN credentials
>> application_id = "xxx"
>> application_key = "xxx"
>>
>> ## set up an instance of Tweepy
>> auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
>> auth.set_access_token(access_token, access_token_secret)
>> api = tweepy.API(auth)
>>
>> ## set up an instance of the AYLIEN Text API
>> client = textapi.Client(application_id, application_key)
>>
>> ## search Twitter for something that interests you
>> query = input("topic? \n")
>> number = input("number of tweets? \n")
>>
>> results = api.search(
>>lang="en",
>>q=query + " -rt",
>>count=number,
>>result_type="recent"
>> )
>>
>> print("--- Gathered Tweets \n")
>>
>> ## open a csv file to store the Tweets and their sentiment
>> file_name = 'Sentiment_Analysis_of_{}_Tweets_About_{}.csv'.format(number, 
>> query)
>>
>> with open(file_name, 'w', newline='') as csvfile:
>>csv_writer = csv.DictWriter(
>>f=csvfile,
>>fieldnames=["Tweet", "Sentiment"]
>>)
>>csv_writer.writeheader()
>>
>>print("--- Opened a CSV file to store the results of your sentiment 
>> analysis... \n")
>>
>> ## tidy up the Tweets and send each to the AYLIEN Text API
>>for c, result in enumerate(results, start=1):
>>tweet = result.text
>>tidy_tweet = tweet.strip().encode('ascii', 'ignore')
>>
>>if len(tweet) == 0:
>>print('Empty Tweet')
>>continue
>>
>>response = client.Sentiment({'text': tidy_tweet})
>>csv_writer.writerow({
>>'Tweet': response['text'],
>>'Sentiment': response['polarity']
>>})
>>
>>print("Analyzed Tweet {}".format(c))
>>
>> ## count the data in the Sentiment column of the CSV file
>> with open(file_name, 'r') as data:
>>counter = Counter()
>>for row in csv.DictReader(data):
>>counter[row['Sentiment']] += 1
>>
>>positive = counter['positive']
>>negative = counter['negative']
>>neutral = counter['neutral']
>>
>> ## declare the variables for the pie chart, using the Counter variables for 
>> "sizes"
>> colors = ['limegreen', 'dodgerblue', 'darkorchid']
>> sizes = [positive, negative, neutral]
>> labels = 'Positif', 'Negatif', 'Netral'
>> explode = (0.1, 0, 0)
>>
>> ## use matplotlib to plot the chart
>> plt.pie(
>> x=sizes,
>> shadow=False,
>> colors=colors,
>> labels=labels,
>> startangle=90,
>> explode=explode,
>> autopct='%1.0f%%'
>> )
>> plt.axis('equal')
>> plt.title("Sentiment of {} Tweets about {}".format(number, query))
>> plt.show()
>>
>>
>> how to execute that file in html web page.
>> let's say in the web page, there are two input texts, topic and number,
>> and when I press the submit button, it executes the python script.
>>
>> I'm new to this Django so please explain it with detail,
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/bb4e6be3-5e89-4c9a-bdb2-80fe24bb2a22%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 

Re: executing python script in html button

2017-11-09 Thread Derek
Hi

Its unlikely anyone on this list will write your code - but the good news 
is that are lots of helpful tutorials from which you can learn to do this; 
for example:

* https://docs.djangoproject.com/en/1.11/intro/tutorial04/
* https://tutorial.djangogirls.org/en/django_forms/
* https://www.simplifiedpython.net/django-forms-tutorial-working-forms/

Its likely though, that you might need to work through some of the other 
material so you can understand how and where forms fit into the overall 
Django approach.

Hope this helps
Derek


On Friday, 3 November 2017 18:08:58 UTC+2, Rizal M. wrote:
>
> I have custom python script for twitter sentiment analysis, let's call it 
> sentiment.py
> it has two inputs, topic query and number of tweets.
>
> this is the full code
>
> import sys
> import csv
> import tweepy
> import matplotlib.pyplot as plt
>
> from collections import Counter
> from aylienapiclient import textapi
>
> if sys.version_info[0] < 3:
>input = raw_input()
>
> ## Twitter credentials
> consumer_key = "xxx"
> consumer_secret = "xxx"
> access_token = "xxx"
> access_token_secret = "xxx"
>
> ## AYLIEN credentials
> application_id = "xxx"
> application_key = "xxx"
>
> ## set up an instance of Tweepy
> auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
> auth.set_access_token(access_token, access_token_secret)
> api = tweepy.API(auth)
>
> ## set up an instance of the AYLIEN Text API
> client = textapi.Client(application_id, application_key)
>
> ## search Twitter for something that interests you
> query = input("topic? \n")
> number = input("number of tweets? \n")
>
> results = api.search(
>lang="en",
>q=query + " -rt",
>count=number,
>result_type="recent"
> )
>
> print("--- Gathered Tweets \n")
>
> ## open a csv file to store the Tweets and their sentiment
> file_name = 'Sentiment_Analysis_of_{}_Tweets_About_{}.csv'.format(number, 
> query)
>
> with open(file_name, 'w', newline='') as csvfile:
>csv_writer = csv.DictWriter(
>f=csvfile,
>fieldnames=["Tweet", "Sentiment"]
>)
>csv_writer.writeheader()
>
>print("--- Opened a CSV file to store the results of your sentiment 
> analysis... \n")
>
> ## tidy up the Tweets and send each to the AYLIEN Text API
>for c, result in enumerate(results, start=1):
>tweet = result.text
>tidy_tweet = tweet.strip().encode('ascii', 'ignore')
>
>if len(tweet) == 0:
>print('Empty Tweet')
>continue
>
>response = client.Sentiment({'text': tidy_tweet})
>csv_writer.writerow({
>'Tweet': response['text'],
>'Sentiment': response['polarity']
>})
>
>print("Analyzed Tweet {}".format(c))
>
> ## count the data in the Sentiment column of the CSV file
> with open(file_name, 'r') as data:
>counter = Counter()
>for row in csv.DictReader(data):
>counter[row['Sentiment']] += 1
>
>positive = counter['positive']
>negative = counter['negative']
>neutral = counter['neutral']
>
> ## declare the variables for the pie chart, using the Counter variables for 
> "sizes"
> colors = ['limegreen', 'dodgerblue', 'darkorchid']
> sizes = [positive, negative, neutral]
> labels = 'Positif', 'Negatif', 'Netral'
> explode = (0.1, 0, 0)
>
> ## use matplotlib to plot the chart
> plt.pie(
> x=sizes,
> shadow=False,
> colors=colors,
> labels=labels,
> startangle=90,
> explode=explode,
> autopct='%1.0f%%'
> )
> plt.axis('equal')
> plt.title("Sentiment of {} Tweets about {}".format(number, query))
> plt.show()
>
>
> how to execute that file in html web page.
> let's say in the web page, there are two input texts, topic and number, 
> and when I press the submit button, it executes the python script.
>
> I'm new to this Django so please explain it with detail,
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bb4e6be3-5e89-4c9a-bdb2-80fe24bb2a22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.