I have the following line in a file that is building up a PHP array and writes it in a txt file on server.:
{exp:channel:entries channel="orders" entry_id_from="{embed:LAST_ID}" sort="desc" dynamic="no"}
AND another file that needs to take an id from database and THIS FILE must be embedded into the ACTION FILE ( the one with the line above ) and the ID to be put into the entry_id_from
LAST_ID file:
<?
include '!mysql.php';
$last_id = #mysql_result(mysql_query('SELECT comanda_id_end FROM output_comenzi ORDER BY id DESC'),0);
if(!$last_id) $last_id = 0;
echo $last_id;
?>
How can I make that the LAST_ID file to get PARSED, take the value and insert it into entry_id_from file? I want to somehow embed The Parsed Mysql File into the ARRay File.
Please help :)
Edited to make this work for PHP on output:
I double checked the EE parse order and it looks like you can make this work with EE parsing on output, but I am not 100% certain.
LAST ID File ('template_group/LAST_ID' EE template). Set to parse PHP on output (per your requirement).
<?
include '!mysql.php';
$last_id = #mysql_result(mysql_query('SELECT comanda_id_end FROM output_comenzi ORDER BY id DESC'),0);
if(!$last_id) $last_id = 0;
?>
// call our embedded template and pass our EE variable forward
{embed="template_group/EXPORT_ACTION_FILE" LAST_ID="<? echo $last_id; ?>"}
Your other file ('template_group/EXPORT_ACTION_FILE' EE template):
{exp:channel:entries channel="orders" entry_id_from="{embed:LAST_ID}" sort="desc" dynamic="no"}
Related
I'm looking for a script (or if there isn't, I guess I'll have to write my own).
I wanted to ask if anyone here knows a script that can take a txt file with n links (lets say 200). I need to extract only links that have particular characters in them, let's say I only need links that contain "/r/learnprogramming". I need the script to get those links and write them to another txt files.
Edit: Here is what helped me: grep -i "/r/learnprogramming" 1.txt >2.txt
you can use ajax to read .txt file using jquery
<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<script>
jQuery(function($) {
console.log("start")
$.get("https://ayulayol.imfast.io/ajaxads/ajaxads.txt", function(wholeTextFile) {
var lines = wholeTextFile.split(/\n/),
randomIndex = Math.floor(Math.random() * lines.length),
randomLine = lines[randomIndex];
console.log(randomIndex, randomLine)
$("#ajax").html(randomLine.replace(/#/g,"<br>"))
})
})
</script>
<div id=ajax></div>
If you are using linux or macOS you could use cat and grep to output the links.
cat in.txt | grep /r/programming > out.txt
Solution provided by OP:
grep -i "/r/learnprogramming" 1.txt >2.txt
Since you did not provide the exact format of the document I assume those links are separated by newline characters. In this case, the code is pretty straightforward using Python/awk since you can iterate over file.readlines() and print only those that match your pattern (either by using a lines.contains(pattern) or using a regex if the pattern is more complex). To store the links in a new file simply redirect the stdout to a new file like this:
python script.py > links.txt
The solution above works even if links are separated by an arbitrary symbol s, first read the file into a single string and split it over s. I hope this helps.
This is a question about Nifi.
I made Nifi pipeline to convert flowfile with xml format to csv format.
Now, I would like to concatenate or union the converted csv flowfile to existing tables by filename (which stands for table name as well).
Simply put, my processor flow is following.
GetFile (from a particular directory) -> 2. Convert xml to csv -> 3.Update the flowfile with table name
-> 4. PutFile (to a different directory)
But, at the end of the flow, PutFile processor throws an error, saying "file with the same name already exists".
I have no ideas how flowfile can be added to existing csv table.
Any advice, tips, ideas are appreciated.
Thank you in advance.
there is no support to append file however you could use ExecuteGroovyScript to do it:
def ff=session.get()
if(!ff)return
ff.read().withStream{s->
String path = "./out_folder/${ff.filename}"
//sync on file path to avoid conflict on same file writing (hope)
synchronized(path){
new File( path ).append(s)
}
}
REL_SUCCESS << ff
if you need to work with text (reader) content rather then byte (stream) content
the following example shows how to exclude 1 header line from flow file if destination file already exists
def ff=session.get()
if(!ff)return
ff.read().withReader("UTF-8"){r->
String path = "./.data/${ff.filename}"
//sync on file path to avoid conflict on same file writing (hope)
synchronized(path){
def fout = new File( path )
if(fout.exists())r.readLine() //skip 1 line (header) only if out file already exists
fout.append(r) //append to the file the rest of reader content
}
}
REL_SUCCESS << ff
I have created my own enduser_setup.html file nodemcu(for the enduser setup module: https://nodemcu.readthedocs.io/en/master/en/modules/enduser-setup/#enduser_setupstart).
I have added another field (beyond the ssid\password fileds):
<input id=result1 type=text autocorrect=off autocapitalize=none placeholder='Place ID' />
I want on submit to create a lua file (result1.lua) with the Get result of this field.
Tried with php:
<?php
$myfile = fopen("result1.lua", "w") or die("Unable to open file!");
$txt = $_GET["result1"];
fwrite($myfile, $txt);
fclose($myfile);
?>
Did not work :(
That is currently not possible with NodeMCU. However, there is a pending pull request that'll add this feature. It's likely going to be merged to the dev branch in the next days.
I need some help with PHPEXCEL library, everything works great, I'm successfully extracting my SQL query to excel5 file, I need to give this file to transport company in order to auto collect informations about packages, unfotunately the generated excel file has some ascii characters between each letter of the cell text, and when the excel file is imported you need to manually delete these charaters.
If I open the excel file, everything is fine I see: COMPANY NAME, If I open the excel file with notepad++, I see the cell values this way: C(NUL)O(NUL)M(NUL)P(NUL)A(NUL)N(NUL)Y N(NUL)A(NUL)M(NUL)E
If I open again the file with excel and save, then reopen with notepad++ I see COMPANY NAME.
So I do not understan why every time I create an excel file using PHPEXCEL my every letter of all words are filled with (nul) every letter.
So how do I prevent the generated excel file to include (nul) between every word????
Also if you open the original excel file generated from PHPExcel samples are also filled with (nul) and if you open and save it, the (nul) is gone.
Any help would be appreciated, thanks.
what is the (nul) ??? 0x00??? char(0)???
ok, here is the example:
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
if (PHP_SAPI == 'cli')
die('Disponibile solo su browser');
require_once dirname(__FILE__) . '/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Solidus")
->setLastModifiedBy("Solidus")
->setTitle("Import web")
->setSubject("Import File")
->setDescription("n.a")
->setKeywords("n.a")
->setCategory("n.a");
$objPHPExcel->setActiveSheetIndex(0)
->setCellValueExplicit("A1", "COMPANY")
->setCellValue('A2', 'SAMSUNG');
$objPHPExcel->getActiveSheet()->setTitle('DDT');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="TEST.xls"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Cache-Control: private',false);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
ob_end_clean();
$objWriter->save('php://output');
As you can see from this little example, this scripts creates a file excel5 with 2 cells, A1 = COMPANY, A2 = SAMSUNG
when I send this file to the transport company, they import the file into their system, but as you can see from the picture, there is an weird character between each letter.
so I noticed every time I open the generated Excel5 with notepad++ file I get:
S(nul)A(nul)M(nul)S(nul)U(nul)N(nul)G
If I save the save with excel and then open it again with notepad++ I get:
SAMSUNG
and this file is ok for the transport company
so my question is, how should I avoid the file generated to contain thi '(nul) charachter between each letter????
some help?
weird characters
SAMSUNG
I found the soluion by myself, I explain just in case anyone has also this problem:
there is not way to change the way the excelfile is encoded by PHPEXCEL
so I figured out the problem was reading the file, I did some simulations and reproduce the problem, every time a read the file and put the result into inputs a get weird characters:
C�O�M�P�A�N�Y�
If I set the output enconding enconding as follows:
$excel->setOutputEncoding('UTF-8');
the file loads fine, so the problem was not creating the excel file, but reading the excel file.
If I print the variable with ECHO I get: "COMPANY",
if I put the variable on input as value I get: "C�O�M�P�A�N�Y�"
setting the output solves the problem, but I would like to know why the difference when I put the variable on input as value, thanks
Using Python 3.5 I have created code to process a file and write output to another file. Following is relevant code;
with open('2016_01_22_Investor_Companies_stops.txt','r') as stops_Investor_Companies:
stops_Investor_Companies = stops_Investor_Companies.read()
stops_Investor_Companies = nltk.word_tokenize(stops_Investor_Companies)
stops_Investor_Companies= [w.lower() for w in stops_Investor_Companies]
stops_Investor_Companies = str(stops_Investor_Companies)
outfile = open ('stops_Investor_Companies_cln.txt', 'w')
outfile.write(stops_Investor_Companies)
print ('1. Investor Companies')
print (' ')
with open('stops_Investor_Companies_cln.txt','r') as fin:
print(fin.read())
print (' ')
The result is that the text 1. Investor Companies prints to the screen but the file stops_Investor_Companies_cln.txt is not printed to the screen.
However, I can print the file stops_Investor_Companies_cln.txt to the screen using same code snippet as a separate script;
with open('stops_Investor_Companies_cln.txt','r') as fin:
print(fin.read())
You are not closing the file before opening it again. Data is flushed in file only after you close it.
Try closing the file before opening it again:-
outfile = open ('stops_Investor_Companies_cln.txt', 'w')
outfile.write(stops_Investor_Companies)
outfile.close()
Or you can use one more with option to open the file so that closing of file is taken care of...
Since you haven't closed the file before opening it again, you're not seeing the new data. What you should do is use another with statement when you open the file for writing so it gets closed properly.