Could anyone tell me how to implement a very single download counter? I mean the followings: Assume you have a folder named media with subfolders such as audio, video, pic. All subfolderes might have another subfolders, e.g. mp3, wav, ra for audio etc. All folder might have files, not just the lowest one. The tricky thing I cannot figure out is how to write a script able to maintain download counts. What I've tried is that I've made the following change to my ZCatalog's search result page: <dtml-in aCatalogue> <a href="fileDownload('<dtml-var sequence-item>')">title_or_id</a><br> </dtml-in> where fileDownload would be a Python script doing the stuff by checking the file's properties. If the file in question has a dwc attribute, it increases its value by one, if does not have, it creates the dwc property and sets its value to 1. The problem is that I cannot reach the object passed to the script. The question is, how to access that passed File object from Python. Can anyone help me?
Hi, You could do it that way, but wouldnt that mean that when you load the page, the link itself will increase the counter whether or not you followed that link, making it ineffective. On our website, I use a query_string that runs a method that increases and THEN fetches the URL, rather than being direct. That way you can also mask the the actual address is necessary. You can check it out in the Links section of our site: www.oratrix.com It may give you an idea or two.... Best regards, Paul Zwarts -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of e-Musty Sent: Monday, November 05, 2001 11:23 AM To: zope@zope.org Subject: [Zope] Download counter Could anyone tell me how to implement a very single download counter? I mean the followings: Assume you have a folder named media with subfolders such as audio, video, pic. All subfolderes might have another subfolders, e.g. mp3, wav, ra for audio etc. All folder might have files, not just the lowest one. The tricky thing I cannot figure out is how to write a script able to maintain download counts. What I've tried is that I've made the following change to my ZCatalog's search result page: <dtml-in aCatalogue> <a href="fileDownload('<dtml-var sequence-item>')">title_or_id</a><br> </dtml-in> where fileDownload would be a Python script doing the stuff by checking the file's properties. If the file in question has a dwc attribute, it increases its value by one, if does not have, it creates the dwc property and sets its value to 1. The problem is that I cannot reach the object passed to the script. The question is, how to access that passed File object from Python. Can anyone help me?
I would also like to implement a download counter. Is there any realistic way of having it count only files that have been _successfully_ and _fully_ downloaded? I know there is a "precondition" for file objects (that can do whatever, e.g. increase a counter), but is there something like a postcondition? I am not sure if this is actually possible, but my feeling is yes. Thanks for your help, Danny On Tuesday 06 November 2001 00:43, Paul Zwarts wrote:
Hi,
You could do it that way, but wouldnt that mean that when you load the page, the link itself will increase the counter whether or not you followed that link, making it ineffective. On our website, I use a query_string that runs a method that increases and THEN fetches the URL, rather than being direct. That way you can also mask the the actual address is necessary. You can check it out in the Links section of our site:
www.oratrix.com
It may give you an idea or two....
Best regards, Paul Zwarts
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of e-Musty Sent: Monday, November 05, 2001 11:23 AM To: zope@zope.org Subject: [Zope] Download counter
Could anyone tell me how to implement a very single download counter? I mean the followings: Assume you have a folder named media with subfolders such as audio, video, pic. All subfolderes might have another subfolders, e.g. mp3, wav, ra for audio etc. All folder might have files, not just the lowest one. The tricky thing I cannot figure out is how to write a script able to maintain download counts. What I've tried is that I've made the following change to my ZCatalog's search result page: <dtml-in aCatalogue> <a href="fileDownload('<dtml-var sequence-item>')">title_or_id</a><br> </dtml-in> where fileDownload would be a Python script doing the stuff by checking the file's properties. If the file in question has a dwc attribute, it increases its value by one, if does not have, it creates the dwc property and sets its value to 1. The problem is that I cannot reach the object passed to the script. The question is, how to access that passed File object from Python. Can anyone help me?
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Danny, I cant say for sure because were quite happy counting downloads after the link was selected and then delivering the file, but I highly doubt that a file could be counted AFTER it was totally downloaded... Only probably way could be to have a link saying 'click here when finished' but people would never do that. You _COULD_ write a filesystem protocol that monitors the TCP/IP layer and watches for a stream, and then interates a counter when the state closes after, but that would be a lot of work for little gain. Cheers, Paul Zwarts -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of Danny William Adair Sent: Monday, November 05, 2001 9:49 PM To: Paul Zwarts; emusty@mailbox.hu; zope@zope.org Subject: Re: [Zope] Download counter - only successful downloads I would also like to implement a download counter. Is there any realistic way of having it count only files that have been _successfully_ and _fully_ downloaded? I know there is a "precondition" for file objects (that can do whatever, e.g. increase a counter), but is there something like a postcondition? I am not sure if this is actually possible, but my feeling is yes. Thanks for your help, Danny On Tuesday 06 November 2001 00:43, Paul Zwarts wrote:
Hi,
You could do it that way, but wouldnt that mean that when you load the page, the link itself will increase the counter whether or not you followed that link, making it ineffective. On our website, I use a query_string that runs a method that increases and THEN fetches the URL, rather than being direct. That way you can also mask the the actual address is necessary. You can check it out in the Links section of our site:
www.oratrix.com
It may give you an idea or two....
Best regards, Paul Zwarts
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of e-Musty Sent: Monday, November 05, 2001 11:23 AM To: zope@zope.org Subject: [Zope] Download counter
Could anyone tell me how to implement a very single download counter? I mean the followings: Assume you have a folder named media with subfolders such as audio, video, pic. All subfolderes might have another subfolders, e.g. mp3, wav, ra for audio etc. All folder might have files, not just the lowest one. The tricky thing I cannot figure out is how to write a script able to maintain download counts. What I've tried is that I've made the following change to my ZCatalog's search result page: <dtml-in aCatalogue> <a href="fileDownload('<dtml-var sequence-item>')">title_or_id</a><br> </dtml-in> where fileDownload would be a Python script doing the stuff by checking the file's properties. If the file in question has a dwc attribute, it increases its value by one, if does not have, it creates the dwc property and sets its value to 1. The problem is that I cannot reach the object passed to the script. The question is, how to access that passed File object from Python. Can anyone help me?
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
I cant say for sure because were quite happy counting downloads after the link was selected and then delivering the file, but I highly doubt that a file could be counted AFTER it was totally downloaded... Only probably way could be to have a link saying 'click here when finished' but people would never do that.
You _COULD_ write a filesystem protocol that monitors the TCP/IP layer and watches for a stream, and then interates a counter when the state closes after, but that would be a lot of work for little gain.
Ahh, naaa. Either some "easy way" or not at all :-) That would just be a goodie. If there is no clear way to do this, I will have to be happy with mere clicks, too. Wouldabeen nice. Thx, Danny
From: "e-Musty" <emusty@mailbox.hu>
where fileDownload would be a Python script doing the stuff by checking the file's properties. If the file in question has a dwc attribute, it increases its value by one, if does not have, it creates the dwc property and sets its value to 1.
I'd discourage this - if you change something in the same object as the media, then the object is appended again to the ZODB, which will cause unneccessary bloat. I'd either have your method update the catalog - you could create a new index for the download count - or have separate associated objects for each file. Perhaps the FSCounter, which is a kind of page counter, or ThreadSafeCounter.
The problem is that I cannot reach the object passed to the script. The question is, how to access that passed File object from Python. Can anyone help me?
Catalog searches don't return the object, but a kind of reference to it - check the zope book for details.
this is more purely a python question as i am using external methods for most of my processing.... SOS,,, perl guy getting squeezed by the snake. so this seems like it should be trivial but as a perl hack just learing, i'm not sure of the syntax, or if i am missing something basic about the dictionary type. so, i have a list of strings that will be used as keys, say:
my_list['K1','K2','K3']
for each of those keys, i would like to create a dictionary that has as its value a dictionary that like the following:
test = {'us_lead': 0, 'foreign_lead': 0, 'us_gov_lead': 0, 'foreign_lead': 0, 'us_other': 0, 'foreign_other': 0 }
for i in my_list: hash_one = {i: ""} hash_one[i] = test
this seems to "reset" the value of has_one with each iteration instead of updating it?? the key should be different, why is this?? -- thanks for all the love, james jackson (aka, jcj@slack.net)
This could be a 'deep copy' issue - check the python.org website. Other thing you could try is: hash_one = {} for i in my_list: hash_one[i] = test The way you had it, you're chucking the old hash_one every iteration, and re-assigning it to a fresh dictionary {i:""}
From: <zope@virtosi.com> Date: Mon, 5 Nov 2001 14:21:14 -0500 (EST) To: <zope@zope.org> Subject: [Zope] Python Q: dynamic dictionary of dictionaries..
this is more purely a python question as i am using external methods for most of my processing.... SOS,,, perl guy getting squeezed by the snake.
so this seems like it should be trivial but as a perl hack just learing, i'm not sure of the syntax, or if i am missing something basic about the dictionary type.
so, i have a list of strings that will be used as keys, say:
my_list['K1','K2','K3']
for each of those keys, i would like to create a dictionary that has as its value a dictionary that like the following:
test = {'us_lead': 0, 'foreign_lead': 0, 'us_gov_lead': 0, 'foreign_lead': 0, 'us_other': 0, 'foreign_other': 0 }
for i in my_list: hash_one = {i: ""} hash_one[i] = test
this seems to "reset" the value of has_one with each iteration instead of updating it?? the key should be different, why is this??
-- thanks for all the love, james jackson (aka, jcj@slack.net)
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On Mon, Nov 05, 2001 at 02:21:14PM -0500, zope@virtosi.com wrote:
test = {'us_lead': 0, 'foreign_lead': 0, 'us_gov_lead': 0, 'foreign_lead': 0, 'us_other': 0, 'foreign_other': 0 }
for i in my_list: hash_one = {i: ""} hash_one[i] = test
this seems to "reset" the value of has_one with each iteration instead of updating it?? the key should be different, why is this??
The first line in your "for" loop creates a new hash_one and discards whatever was in hash_one previously. At the end of the loop, hash_one will only contain one key - the last one in the loop. Try this: hash_one={} for i in my_list: hash_one[i] = test But I suspect that will just lead you to a new puzzle: you now have a dictionary (hash_one) whose keys all point to the same dictionary (test). The problem is that I suspect you'll want to modify them independently. And the first time you try it, if you do hash_one['K1']['us_lead'] = 99, guess what ... hash_one['k2']['us_lead'] is now also 99. I suspect that's not what you want. In python, if you assign the same object to several names (or in this case to several values in a dict.), you don't get a new copy for each assignment unless you explicitly ask for one. You can get a copy of a list by slicing the whole thing (e.g. my_list[:]), or a copy of a dictionary by using its copy method (e.g. mydict.copy()), but I like to be consistent and use the copy module from the standard library for everything. Like so: import copy hash_one={} for i in my_list: hash_one[i] = copy.copy(test) -- paul winkler home: http://www.slinkp.com music: http://www.reacharms.com calendars: http://www.calendargalaxy.com
participants (6)
-
Danny William Adair -
e-Musty -
marc lindahl -
Paul Winkler -
Paul Zwarts -
zope@virtosi.com