2

I have a feed set up to use the HTTP Fetcher with CSV Parser to download my content from a URL using the Feeds module (7.x-2.0-alpha8+84-dev) and Feeds Tamper module (7.x-1.0). I've mapped out my fields appropriately, but I'm having difficultly with the instance.

In my CSV source, there's one field where the information source outputs: [[u'short', u'introduced', u'Solar Energy and Energy Conservation, Bank Reauthorization Act of 1983'], [u'official', u'introduced', u'A bill to amend the Solar Energy and Energy Conservation Bank Act to authorize appropriations for the provision of financial assistance under such Act through fiscal year 1990, and for other purposes.']]

However, I only really need the official title pulled into my content, which should be "A bill to amend the Solar Energy and Energy Conservation Bank Act to authorize appropriations for the provision of financial assistance under such Act through fiscal year 1990, and for other purposes."

Is it possible to rewrite this with Feeds Tamper, and if so, which plugin would you use/how would you set this up? In this instance, I don't believe explode would work because I do not want both items in my content and I would like the brackets '[]' and such removed. If not possible, how would you suggest accomplishing my goal?

I'm happy to provide more information, and I very much appreciate any assistance. tia

Here's the link to the source location. I've limited the results to 1 as to not overwhelm :)

  • Don't have time for a full answer, but I would tackle it with a custom tamper plugin. They are pretty easy to write. – mpdonadio Apr 17 '15 at 20:34
0

I agree with MPD. Plugins are easy to write. That looks like a serialised Python object. Is that right?

If you want to avoid that then I think your only option is the regular expression tamper. Use a site that allows you too test your expression on your sample string to help get it right while being fuzzy enough to handle edge cases. Here's one.

https://regex101.com

This seems to work though I'm not 100% on why it only returns the last match so use with caution. Match is in $2.

\[{2}.+?\],\s*\[(u'(.+?)'\,*\s*)+\]{2}

Actually this might be more robust. Match is in $1.

\[{2}.+?\],\s*\[.+\,\s{0,1}u'(.+?)'\]{2}$

https://regex101.com/r/qQ0cC0/3

  • Thanks Queenvictoria, your answer was right on! I can't thank you enough! So for others that might find this post, I added Feeds Tamper 'Find replace REGEX' with REGEX to find: /[{2}.+?],\s*[.+\,\s{0,1}u'(.+?)']{2}$/ – tracyt10 Apr 22 '15 at 22:35
  • In my particular case, I had to add an additional Find replace REGEX filter because the data source had a single result in some instances. (ie [[u'official', u'introduced', u'A bill to require the Secretary of Energy to establish an energy efficiency retrofit pilot program.']]) That turned out to be: /\s*[.+\,\s{0,1}u'(.+?)']{2}/ – tracyt10 Apr 22 '15 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.